Skip to content

Instantly share code, notes, and snippets.

@leixingyu
Created August 21, 2023 22:56
Show Gist options
  • Save leixingyu/3344614024d3490085346ad6f0af1b41 to your computer and use it in GitHub Desktop.
Save leixingyu/3344614024d3490085346ad6f0af1b41 to your computer and use it in GitHub Desktop.
Conform plain text as Python executable command
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