Run python source file from PowerShell

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'
+3
source share
6 answers

Python , . , python exe .

+2

, โ€‹โ€‹ Python, IDLE . , python , >python -V . , . , >python C:\myfile.py.

Python, , script, python. . >myfile.py

, C:\Python27 %PATH% .PY %PATHEXT% . >myfile.

:

>python python " ", , script. , , script sys.argv.

+3

: PowerShell, cmd.exe.

, python myfile.py , , PowerShell cmd.exe, , : myfile.py. , Python script enter.

+1

"python" powershell, script.

If you are in python type:

quit() then enter python myfile.py

This should work if your python is set correctly.

0
source

Try entering this in Powershell:

$env:path="$env:Path;C:\Python33

After this command

python yourfile.py

must work.

0
source

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

0
source

All Articles