how to input python code in run time and execute it?

后端 未结 3 1417
一个人的身影
一个人的身影 2021-01-17 06:52

Well i want to input a python function as an input in run time and execute that part of code \'n\' no of times. For example using tkinter i create a textbox where the user w

相关标签:
3条回答
  • 2021-01-17 07:01

    Python provides number of ways to do this using function calls: - eval() - exec()

    For your needs you should read about exec.

    0 讨论(0)
  • 2021-01-17 07:10

    That's what execfile() is for.

    http://docs.python.org/library/functions.html#execfile

    1. Create a temporary file.

    2. Write the content of the textbox into the file.

    3. Close.

    4. Execfile.

    5. Delete when done.

    0 讨论(0)
  • 2021-01-17 07:22

    Would IPython do?

    Doc: http://ipython.scipy.org/moin/Documentation

    0 讨论(0)
提交回复
热议问题