Jump to content

Utilising Python


physica

Recommended Posts

I'm starting to learn python for post grad. However, I am having trouble utilising it. I can run code in the terminal via text wrangler. This works fine however, if I try and run it by itself it comes up with

 

NameError: name raw_input("Enter name: ")

 

I then downloaded IDLE and python launcher from python.org. However, it gives the same error message. It seems that I can only run by code through the terminal (I'm on mac). I am also at a loss on how to compile programs. I have no idea how to use python launcher and I can't find any tutorials. Can anyone point me in the right direction for guidance?

 

Many thanks

Link to comment
Share on other sites

Do you need to add a line to the Python code file telling the shell to load the python interpreter?
the first line has to be: "#!/bin/python" (no quotes) for bash on Linux but it might be different on your OS
If you dig around Python.org for a while, you'll probably find the answer look for python script for the shell or so.

Link to comment
Share on other sites

Do you need to add a line to the Python code file telling the shell to load the python interpreter?

the first line has to be: "#!/bin/python" (no quotes) for bash on Linux but it might be different on your OS

 

It's the path to the .exe file you are using not #!/bin/python it just tends to be installed there on Linux.

Link to comment
Share on other sites

I'm starting to learn python for post grad. However, I am having trouble utilising it. I can run code in the terminal via text wrangler. This works fine however, if I try and run it by itself it comes up with

 

NameError: name raw_input("Enter name: ")

 

I then downloaded IDLE and python launcher from python.org. However, it gives the same error message. It seems that I can only run by code through the terminal (I'm on mac). I am also at a loss on how to compile programs. I have no idea how to use python launcher and I can't find any tutorials. Can anyone point me in the right direction for guidance?

 

Many thanks

It looks like your version of IDLE is python 3 and your version of input is python 2.

Link to comment
Share on other sites

Thanks for the input. To be honest I am very new to this so when you guys talk about shells etc I am a bit lost. Is there a download you can recommend for a starter? I want to get used to the syntax and write some very basic programs so I can get a hang of the basics. Yes I downloaded python 3 but I have been learning how to code from code academy.com. I am not sure if codeacademy.com is teaching in python 2.

Link to comment
Share on other sites

Python.org says codeacademy is using python 2.0.
The shell or CLI is generally when you are typing commands or program names to be executed instead of clicking on an icon with a mouse.
"how to think like a computer scientist" had some good tutorals, but it looks like it's been updated since the last time I was there so it may or may not be worth checking.

Link to comment
Share on other sites

Many thanks. I have downloaded python 2 from python.org and it runs with no problems. Considering that I have gotten fairly far on code academy and I will not be writing the most complex programs I will stick with this. Many thanks for the help. Before this thread I didn't even know there was 2 versions of python. Will look into compilers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.