在Python Shell中运行程序

编程入门 行业动态 更新时间:2024-10-27 06:33:18
本文介绍了在Python Shell中运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个演示文件:test.py. 在Windows控制台中,我可以使用以下命令运行文件:C:\>test.py

I have a demo file: test.py. In the Windows Console I can run the file with: C:\>test.py

我该如何在Python Shell中执行文件?

How can I execute the file in the Python Shell instead?

推荐答案

使用 execfile 用于 Python 2 :

>>> execfile('C:\\test.py')

对于 Python 3 使用 exec

>>> exec(open("C:\\test.py").read())

更多推荐

在Python Shell中运行程序

本文发布于:2023-10-07 14:47:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469680.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   Python   Shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!