Created
July 19, 2020 12:30
-
-
Save raeq/2907fb033de5c35f4fb140400345dc72 to your computer and use it in GitHub Desktop.
Execute code found in strings
This file contains hidden or 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
import subprocess | |
import ast | |
def exec_string(input_string: str = "") -> str: | |
result = subprocess.getoutput(input_string) | |
return result | |
def eval_string(input_string: str = "") -> str: | |
result = ast.literal_eval(input_string) | |
return str(result) | |
assert exec_string("ls -l") | |
assert eval_string("{ 'key':'value' }") == "{'key': 'value'}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment