如何从IDLE交互式shell运行python脚本?

问题描述:

如何在IDLE交互式shell中运行python脚本?

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

以下引发错误:

>>> python helloworld.py
SyntaxError: invalid syntax


内置函数: execfile

execfile('helloworld.py')

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

高级用法: 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 :-)