我想启动一个python脚本(file.py)
为此,我在Python解释器中复制了该文件的路径,但得到错误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()发布于 2018-05-04 22:11:50
如果你只想运行一个脚本,那么语法是(从你的system__shell,__not python shell):
$ python path/to/your/script.py如果想要在现有的python shell中执行,可以(在python shell中)运行:
>>> execfile("path/to/your/script.py")发布于 2018-05-04 22:16:16
你可以运行
python<version> <path>示例:
Python3 test.py从您的错误看,您似乎正确地运行了它,但代码包含编译错误。添加代码片段,这样我们就可以看到问题出在哪里
发布于 2018-05-07 17:35:28
我无法从Windows控制台启动Python脚本,因为我没有添加变量PATH。
因此,我在YouTube教程后面添加了变量path:https://www.youtube.com/watch?v=uXqTw5eO0Mw
然后,当我试图启动脚本时,我得到了一个错误“没有找到这样的文件或目录”。这是因为我没有在脚本"C:\ ...“的路径中放一个空格。不是"C:\“
最后,我收到一条消息"python.exe无法找到'main‘模块“。这是因为我需要再次使用".py“扩展名保存我的脚本。
https://stackoverflow.com/questions/50176925
复制相似问题