首页 > 解决方案 > 如何从 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()

标签: pythonwindowscmdlaunch

解决方案


你可以跑

python<version> <path>

例子:

Python3 test.py

从您的错误看来,您运行正确,但代码包含编译错误。添加代码片段,以便我们可以看到问题出在哪里


推荐阅读