Learn Python the Hard Way, Ex 2; Powershell not outputting ex1.py?

Viewed 161

I am very new to the language so I might need an ELI5 for the response.

I've created my ex1.py, checked all of the casing and syntax and it appears to be right?

print "Hellow World!"
print "Hello again"
print "i like typing this" 
print "this is fun"
print 'Yay! printing!' 
print "I'd much rather you 'n'."
print 'I "said" do not touch this!'

When I type: python ex1.py in terminal after navigating to the proper folder, the terminal displays the script, not powershell. I've tried entering

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

etc. string that is on page 8 of the book into PowerShell, but that doesn't seem to help.

In the filepath above, should I be replacing C:\Python27 with the literal filepath of where i have Python installed? Likewise, "User" with my username? Or do I enter the string literally as is?

2 Answers

Your code is fine but it seems your environment is not set correctly. Do the following:

  1. Start powershell
  2. [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\<directory_where_python.exe in installed>", "User")

  3. Restart powershell (close it, then start it back up again)

  4. Cd in directory that contains ex1.py

  5. Execute python .\ex1.py

Please see if you have saved the file ex1.py properly.Check once.

You may have saved the file name first and later typed in the notepad and forgot to save the file.

Related