如何从Windows Shell启动python脚本?
我想启动一个python脚本(file.py) 为了做到这一点,我在Python解释器中复制了该文件的路径,但得到了错误如何从Windows Shell启动python脚本?,python,windows,cmd,launch,Python,Windows,Cmd,Launch,我想启动一个python脚本(file.py) 为了做到这一点,我在Python解释器中复制了该文件的路径,但得到了错误SyntaxError:unexpected character after line continuation character 我是初学者,这是迄今为止我发现的最简单的启动Python脚本的方法。。。如果你有一个更简单的方法,我愿意接受提示 多谢各位 下面是我的Python脚本: import os import csv ACCEPTED_MSG=""" Hi {},
SyntaxError:unexpected character after line continuation character
我是初学者,这是迄今为止我发现的最简单的启动Python脚本的方法。。。如果你有一个更简单的方法,我愿意接受提示
多谢各位
下面是我的Python脚本:
import os
import csv
ACCEPTED_MSG="""
Hi {},
We are thrilled to let you know that you are accepted to our
programming workshop.
Your coach is {}.
Can't wait to see you there !
Thank you,
Workshop Organizers
"""
REJECTED_MSG="""
Hi {},
We are verry sorry to let you know that due to a big number
of applications we couldn't fit you at the workshop this time...
We hope to see you next time.
Thank you,
Workshop Organizers
"""
path_to_file = "C:/Users/Julien/Downloads/data.csv"
file_exists = os.path.exists(path_to_file)
if file_exists:
csv_file = open(path_to_file)
csv_reader = csv.reader(csv_file, delimiter=',')
next(csv_reader)
for row in csv_reader:
name, email, accepted, coach, language = row
print (name, email, accepted, coach, language)
if accepted =='Yes':
msg = ACCEPTED_MSG.format(name, coach)
else:
msg = REJECTED_MSG.format(name)
print ("Send e-mail to: {}".format(email))
print("E-mail content:")
print (msg)
csv_file.close()
如果您只想运行一个脚本,那么语法是(从系统\uuuuuu shell中,\uuuu而不是从python shell中): 如果要在现有python shell中执行,可以运行(在python shell中):
如果您只想运行一个脚本,那么语法是(从系统\uuuuuu shell中,\uuuu而不是从python shell中): 如果要在现有python shell中执行,可以运行(在python shell中): 你可以跑
python<version> <path>
从您的错误来看,您似乎正确地运行了它,但代码包含编译错误。添加代码片段,以便我们可以看到问题出在哪里您可以运行
python<version> <path>
从您的错误来看,您似乎正确地运行了它,但代码包含编译错误。添加代码片段以便我们可以看到问题出在哪里我无法从Windows控制台启动Python脚本,因为我没有添加变量路径 因此,我在YouTube教程之后添加了变量路径: 然后,当我试图启动脚本时,出现了一个错误“找不到这样的文件或目录”。这是因为我没有在脚本“C:\…”的路径中放置空格,而不是“C:\”
最后,我收到一条消息“python.exe找不到“main”模块”。这是因为我需要再次使用“.py”扩展名保存脚本。我无法从Windows控制台启动Python脚本,因为我没有添加变量路径 因此,我在YouTube教程之后添加了变量路径: 然后,当我试图启动脚本时,出现了一个错误“找不到这样的文件或目录”。这是因为我没有在脚本“C:\…”的路径中放置空格,而不是“C:\”
最后,我收到一条消息“python.exe找不到“main”模块”。这是因为我需要再次使用扩展名“.py”保存脚本。在命令行上运行
python file.py
。在命令行上运行python file.py
>>>python C:\Users\Julien\Desktop\python\python 3\CIFG\python Basics\Reading Da From CSV.py file”“,第1行python C:\Users\Julien\Desktop\python\python 3\CIFG\python Basics\Reading Da ta From CSV.py^syntaxer错误:无效syntax@JulienBlomme抱歉,我没有说清楚:第一种语法是从系统shell运行脚本,不是从python shell中。python C:\Users\Julien\Desktop\python\python 3\CIFG\python Basics\Reading Da ta from CSV.py File”“,第1行python C:\Users\Julien\Desktop\python\python 3\CIFG\python Basics\Reading Da ta From CSV.py^syntaxer错误:无效syntax@JulienBlomme抱歉,我没有说清楚:第一种语法是从系统shell运行脚本,不是来自python shell。我认为SyntaxError来自于实际尝试将python shell用作系统shell的OP;)正如@bruno desthuillers所建议的,可能是pyShell上错误的ommand导致的sintax错误,完全有道理,让我们保持更新^^有人知道synthax吗?我在谷歌上搜索这个,但是找不到任何东西,为什么?没有';我们的答案没有解决您的问题吗?在Python解释器外壳中启动脚本的语法。。。我想我找到了目前正在阅读的有用信息……我认为SyntaxError来自于OP,它实际上试图将pythonshell用作系统shell;)正如@bruno desthuillers所建议的,可能是pyShell上错误的ommand导致的sintax错误,完全有道理,让我们保持更新^^有人知道synthax吗?我在谷歌上搜索这个,但是找不到任何东西,为什么?没有';我们的答案没有解决您的问题吗?在Python解释器外壳中启动脚本的语法。。。我想我找到了目前正在阅读的有用信息。。。
python<version> <path>
Python3 test.py