3

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?

5
  • 1
    @TheJoelteon What are you expecting to happen in your script versus what is happening? Commented Nov 9, 2017 at 17:21
  • Your code is fine. Must be an environment problem. What's the exact output when you execute python ex1.py in the folder that contains ex1.py? Commented Nov 9, 2017 at 17:26
  • "should i be replacing C:\Python27 with the literal filepath of where i have Python installed?" -> Yes! there's no reason to use the default path if you've installed Python somewhere else. Commented Nov 9, 2017 at 17:27
  • Maybe we need to get even more basic information. What happens when you just type python and hit Enter in a terminal window? Commented Nov 9, 2017 at 17:28
  • Also, you need to restart powershell in order for it to load the new value of the Path variable. Commented Nov 9, 2017 at 17:31

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

4 Comments

Edit: python .\ex1.py if you're in PowerShell.
@TheIncorrigible1 Hmm, I'm pretty sure ex1.py assumes the current directory, no?
It's a PS best-practice to avoid ambiguity since it doesn't parse in the same way cmd did.
should it look like this? imgur.com/a/gczyF Edit: i dont know what i did wrong :\ both the terminal and powershell are displaying the same thing for all that i can see; according to the book, i should type python ex1.py and ex1 should display in powershell. it isnt.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.