I am trying to learn python, but have some problems running the source files from the shell. When I type "python", it opens, and I can enter python commands directly into the shell. I think this is called interactive mode. But when I try to run / execute the source file, I get the error message: This is sayys: Syntax error: invalid syntax.
I use 'python myfile.py' when I try to execute a script.
If I run the same file from IDLE, it works fine. Ana thinks I'm doing wrong?
Here is myfile.py. I am running python 2.7
# filename: myfile.py while True: s = raw_input('Enter something: ') if s == 'Quit': break print 'Lenght of the string is', len(s) print 'Done'
Python , . , python exe .
, โโ Python, IDLE . , python , >python -V . , . , >python C:\myfile.py.
>python -V
>python C:\myfile.py
Python, , script, python. . >myfile.py
>myfile.py
, C:\Python27 %PATH% .PY %PATHEXT% . >myfile.
C:\Python27
%PATH%
.PY
%PATHEXT%
>myfile
:
>python python " ", , script. , , script sys.argv.
>python
sys.argv
: PowerShell, cmd.exe.
, python myfile.py , , PowerShell cmd.exe, , : myfile.py. , Python script enter.
python myfile.py
myfile.py
"python" powershell, script.
python
powershell
If you are in python type:
quit() then enter python myfile.py
quit()
This should work if your python is set correctly.
Try entering this in Powershell:
$env:path="$env:Path;C:\Python33
After this command
python yourfile.py
must work.
This is my stupid sound, especially from a beginner.
Just save the file to your desktop. Open powershell and drag the file directly into powershell and it opens. something tedious but it works