600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > idle运行python_如何从IDLE交互式shell运行python脚本?

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

时间:2023-12-29 02:16:13

相关推荐

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 :-)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。