本文介绍了在交互模式下是否可以执行Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常您可以执行Python脚本,例如:python myscript.py,但是如果您处于交互模式,那么如何在文件系统上执行Python脚本呢?

Normally you can execute a Python script for example: python myscript.py, but if you are in the interactive mode, how is it possible to execute a Python script on the filesystem?

>>> exec(File) ???

应该可以多次执行该脚本.

It should be possible to execute the script more than one time.

推荐答案

使用 execfile ('script.py'),但仅适用于python 2.x,如果您使用的是3.0,请尝试

Use execfile('script.py') but it only work on python 2.x, if you are using 3.0 try this

这篇关于在交互模式下是否可以执行Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 07:11