How to run a python script from IDLE interactive shell?

前端 未结 15 1812
無奈伤痛
無奈伤痛 2020-11-30 17:25

How do I run a python script from within the IDLE interactive shell?

The following throws an error:

>>> python helloworld.py
SyntaxError: i         


        
相关标签:
15条回答
  • 2020-11-30 18:27

    For example:

    import subprocess
    
    subprocess.call("C:\helloworld.py")
    
    subprocess.call(["python", "-h"])
    
    0 讨论(0)
  • 2020-11-30 18:28

    you can do it by two ways

    • import file_name

    • exec(open('file_name').read())

    but make sure that file should be stored where your program is running

    0 讨论(0)
  • 2020-11-30 18:30

    There is one more alternative (for windows) -

        import os
        os.system('py "<path of program with extension>"')
    
    0 讨论(0)
提交回复
热议问题