如何使用 python 命令执行 Python 脚本 [英] How to execute Python scripts with python command
问题描述
我想使用来自 IDLE Python GUI 的 python
命令运行 Python 脚本.
该文件的位置是 C:\Users\DELL\Desktop\Hello.py
当我使用 Windows 命令提示符运行 python C:\Users\DELL\Desktop\Hello.py
时,它可以工作.但是,当我尝试使用 IDLE Python GUI 和 Python(命令行)时,它不起作用并给我一条消息 SyntaxError: invalid syntax
捕获
在 python shell 中,你可以import
模块.这样,一旦你导入它,你就可以在shell上看到Hello".
I want to run the Python Script by using python
command from IDLE Python GUI.
The location of the file is C:\Users\DELL\Desktop\Hello.py
When I run python C:\Users\DELL\Desktop\Hello.py
with Windows command promt, it works. However, when I try with IDLE Python GUI and Python (command line), it does not work and gives me a message SyntaxError: invalid syntax
Capture
inside python shell, you can import
the module. This way, you can see "Hello" printed on shell once u import it.
>>> import sys
>>> sys.path.append('C:\Users\DELL\Desktop')
>>> import Hello
"Hello"
这篇关于如何使用 python 命令执行 Python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!