Created
August 21, 2023 22:56
-
-
Save leixingyu/3344614024d3490085346ad6f0af1b41 to your computer and use it in GitHub Desktop.
Conform plain text as Python executable command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def conform(txt): | |
""" | |
Conform plain text as Python executable command | |
this can be useful for whenever we need to get python | |
as plain text format from a text widget and execute that | |
for example: | |
exec(command) | |
mel.eval('python({})'.format(command)) | |
unreal.PythonScriptLibrary.execute_python_command_ex(command) | |
""" | |
command = txt.replace('\\', r'\\') # first handle '\' (escape) | |
command = command.replace('\n', r'\n') # what does this do? | |
command = command.replace(r'\\n', r'') # handle line continuation | |
command = command.replace(r'"', r'\"') | |
return command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment