-1

Is there a way to get a string from a user and convert it into a python code?

 let pyString = """

     start = 'hello'
     end = 'world'
     print(start + ' ' + end)

 """

 func py(input: String) {
 //  run input as python

 }

 py(input: pyString)
 // output: "Hello world"
1

1 Answer 1

1

there are several ways to do that . You can invoke the system interpreter subprocess.run(...) with option -c and pass the commands as string.

You can also save the string to a file and execute it with the system interpreter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.