python - 如何从 Windows Shell 启动 python 脚本?
问题描述
我想启动一个 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()
解决方案
你可以跑
python<version> <path>
例子:
Python3 test.py
从您的错误看来,您运行正确,但代码包含编译错误。添加代码片段,以便我们可以看到问题出在哪里
推荐阅读
- java - Java 中的 .length 关键字定义在
- r - 从数据中去除时间部分并使用 R 计算连续行之间的时间差
- google-apps-script - GAS 类电子表格应用程序:追加行和合并单元格
- python-3.x - 重新使用华为调制解调器 E3372h 的令牌
- java - Java 错误 1876 --- [主要] osbdLoggingFailureAnalysisReporter:
- jekyll - 从 Jekyll 帖子创建图像
- c# - 自定义错误页面未显示在网站上,但在 Visual Studio 中运行时会显示
- python - 如何修复 ValueError:无法将字符串转换为浮点数
- bash - Bash函数没有返回预期的输出
- excel-formula - Excel公式如果那么