0

I would like to launch a python script (file.py)

In order to do this I copied the path of this file in the Python interpreter but I get the error SyntaxError: unexpected character after line continuation character

I am beginner and this is the simplest way to launch Python script I found so far... If you have a simpler way I'm open to tips...

Thank you

Here's my Python script:

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()
1
  • On the command line, run python file.py. Commented May 4, 2018 at 14:10

3 Answers 3

2

You can run

python<version> <path>

Example:

Python3 test.py

from your error seems like you ran it correctly but the code contains compilation error. Add the code snippet so we can see where is the problem

Sign up to request clarification or add additional context in comments.

5 Comments

I think that the SyntaxError comes from the OP actually trying to use the python shell as a system shell ;)
As suggested by @bruno desthuillers it might was a sintax error from the wrong ommand on the pyShell , make perfectly sense , keep us updated ^^
Does someone know the synthax ? I'm googling this but finding nothing
Systax for what? Didn&#39;t our answer solved your issue?
Syntax to launch a script in the Python interpreter shell ... I think I found useful information I'm reading at the moment ...
2

If you just want to run a script then the syntax is (from your system__shell, __not the python shell):

$ python path/to/your/script.py

If you want to execute from within an existing python shell, you can run (in the python shell):

>>> execfile("path/to/your/script.py")

2 Comments

>>> python C:\Users\Julien\Desktop\Python\Python 3\CIFG\Python Basics\Reading Da ta From CSV.py File "<stdin>", line 1 python C:\Users\Julien\Desktop\Python\Python 3\CIFG\Python Basics\Reading Da ta From CSV.py ^ SyntaxError: invalid syntax
@JulienBlomme sorry I did not made my point clear: the first syntax is to run a script from your system shell, not from within a python shell.
1

I wasn't able to launch a Python script from the Windows console because I haven't added the variable PATH.

So I added the variable path following this YouTube Tutorial: https://www.youtube.com/watch?v=uXqTw5eO0Mw

Then, I got an error "No such File or directory found" when I was trying to launch the script. That was because I didn't put a SPACE in the path to the script "C: \ ..." instead of "C:\"

Finally, I had a message "python.exe can't find 'main' module". It was because I needed to save my scripts with the ".py" extension once again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.