Reputation: 41
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()
Upvotes: 0
Views: 2645
Reputation: 41
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.
Upvotes: 1
Reputation: 77902
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")
Upvotes: 2
Reputation: 365
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
Upvotes: 2