idle运行python_如何从IDLE交互式shell运行python脚本?
How do I run a python script from within the IDLE interactive shell?
The following throws an error:
>>> python helloworld.py
SyntaxError: invalid syntax
解決方案
Built-in function: execfile
execfile('helloworld.py')
Deprecated since 2.6: popen
import os
os.popen('python helloworld.py') # Just run the program
os.popen('python helloworld.py').read() # Also gets you the stdout
Advance usage: subprocess
import subprocess
subprocess.call(['python', 'helloworld.py']) # Just run the program
subprocess.check_output(['python', 'helloworld.py']) # Also gets you the stdout
Read the docs for details :-)
總結
以上是生活随笔為你收集整理的idle运行python_如何从IDLE交互式shell运行python脚本?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 45个photoshop动作免费下载 简
- 下一篇: 性价比高的电视机有哪些