如何从IDLE交互式shell运行python脚本? [英] How to run a python script from IDLE interactive shell?

查看:696
本文介绍了如何从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 :-)

这篇关于如何从IDLE交互式shell运行python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆