Reputation: 2850
Using Python3.3
Trying to run a script from python command line. Need to run this from python command line instead of windows command line because of some encoding format issue. But I am getting below error:
>>> python Start.py
File "<stdin>", line 1
python Start.py
^
SyntaxError: invalid syntax
I think I am already within Python so the above is invalid. I tried execfile but that doesn't help either.
Can anyone please help?
EDIT
The problem with running the script from python command line is solved. Although that doesn't solve the original encoding issue. See the thread here Changing the preferred encoding for Windows7 command prompt
Upvotes: 0
Views: 19559
Reputation: 57
For Windows, we must write
C:\Python31\python.exe test.py > results.txt
// that is from CMD
- from the Summersfeld's evergreen "Programming in Python 3 - A Complete intro".
And if we have an environment variable for python, we don't even need the C:\Python31\
part just
C:\>python.exe test.py > results.txt
Upvotes: 0
Reputation: 78650
You are already running Python, so there's no need to run the python
command.
execfile
is gone in Python3, but you can do it like this:
with open("Start.py") as f:
c = compile(f.read(), "Start.py", 'exec')
exec(c)
Upvotes: 2