PDA

View Full Version : Learning Python




nashyo
Aug 2, 2012, 06:08 AM
Learning other languages is helpful when developing for iOS or anything in fact. This is what I'm told and I believe it.

However, I tried to learn python this morning for the very first time and I have spent all morning and not type one line of python code.

Apparently python is already installed on all Mac's these days but it may not be the latest version of python. So I download the latest version from python.org.

I also look for a decent IDE and I come across eclipse. Eclipse apparently needs some additional plug in software installed called pydev so I look for that and install it.

I then find out that I need to hook up the python interpreter in eclipse, which makes sense, so I hook it up and I get an error message saying the versions are incompatible.

I assumed the latest version of python, eclipse and pydev would be ok. What a waste of time.

So I figure, hey...let's just use terminal. There's probably loads of support for using python in terminal out there...

I was right. After a few searches I find loads of support, but almost all the tutorials I watch are not basic enough. I now I feel really really stupid!

For instance, one guy says create a python file on your desktop...HOW?
Another guy says type vi <filename>.py and then type the following code etc etc...but he didn't mention to cd first to the place you want the file to end up. Also, he said....then run the file...HOW?

Does anyone have a resource for THE MOST BASIC WAY to run Python in a terminal environment FOR A COMPLETE NOOB please?



Cromulent
Aug 2, 2012, 06:30 AM
Here you go.


Open Terminal
Type nano test.py
Add code and save it
Close nano
Type "python test.py" (without the quotes) and press return
See the results of your program
Job done


There is really no need for an IDE. If you want to use something a bit more powerful than nano then Vim or Emacs are the text editors to learn.

Edit: It sounds like you downloaded Python 3.x originally. This is an incompatible language to Python 2.x. If you are just starting the majority of Python documentation on the web assumes you are using Python 2.x which is what comes bundled with Mac OS X.

balamw
Aug 2, 2012, 07:05 AM
There is really no need for an IDE. If you want to use something a bit more powerful than nano then Vim or Emacs are the text editors to learn.

Nothing wrong with a GUI editor like TextWrangler or Fraise/Smultron ... either.

B

Fed
Aug 2, 2012, 07:13 AM
Judging by your post, you should really learn more about computers before you start hacking Python code. You could do some serious damage. The fact you can't create a Python file (literally a computer file with .py at the end) says you really should stay away from the Python interpreter until you know some basics.

I don't mean to be a dismissive but seriously, you aren't going to program anything useful until you know what you're doing.

msdarkroom
Aug 2, 2012, 04:43 PM
Might want to consider this:

http://learnpythonthehardway.org/book/index.html

SteelWheel
Aug 2, 2012, 05:39 PM
If we're really concerned about OP hosing his machine in an effort to learn Python, then how about doing this?

Assuming his machine is running Lion or ML, he can always run Lion within Lion on a VM, and use the VM version as the environment in which to learn Python. If things get out of hand, just blow away the VM and start over.

thekev
Aug 3, 2012, 01:51 AM
Might want to consider this:

http://learnpythonthehardway.org/book/index.html

I went through that one. I wanted to know python as it's a common scripting language. Your link contains one of the greatest quotes ever, although it suggests that I will eventually migrate to Linux:D.



A programmer will eventually tell you to use Mac OSX or Linux. If the programmer likes fonts and typography, they'll tell you to get a Mac OSX computer. If they like control and have a huge beard, they'll tell you to install Linux. Again, use whatever computer you have right now that works. All you need is gedit, a Terminal, and python.

nashyo
Aug 3, 2012, 04:17 AM
thanks for the info guys. learning python the hard way seems like a good link, so i'll give that a try.

i didn't realise the Mac OS Lion licence permitted Virtual Machines?

Ap0ks
Aug 3, 2012, 06:11 AM
Take a look at the Google Python class, it runs through quite a lot including getting your machine setup to write and execute simple Python scripts.

http://code.google.com/edu/languages/google-python-class/index.html

philosopherdog
Aug 3, 2012, 07:01 AM
Python comes with its own IDE called idle. Just install it and look at a couple of YouTube videos. It's very easy to use and free. Avoid eclipse for now. It's a nightmare to set up and in any case a rather poor IDE for python.

nashyo
Aug 3, 2012, 08:51 AM
I went through that one. I wanted to know python as it's a common scripting language. Your link contains one of the greatest quotes ever, although it suggests that I will eventually migrate to Linux:D.

This is a good one

"An 'octothorpe' is also called a 'pound', 'hash', 'mesh', or any number of names. Pick the one that makes you chill out."

Haha

Pivs
Aug 3, 2012, 09:01 AM
Codecademy just added some Python exercises. I haven't tried any of them out yet though, so I can't vouch for them.

http://www.codecademy.com/

Cromulent
Aug 3, 2012, 09:04 AM
This is a good one

"An 'octothorpe' is also called a 'pound', 'hash', 'mesh', or any number of names. Pick the one that makes you chill out."

Haha

Hold me back!

Americans calling the hash symbol the pound symbol drives me mad. The pound symbol is "" mmmkay?

thekev
Aug 3, 2012, 09:07 AM
This is a good one

"An 'octothorpe' is also called a 'pound', 'hash', 'mesh', or any number of names. Pick the one that makes you chill out."

Haha

That author is just completely awesome.

nashyo
Aug 3, 2012, 09:42 AM
Having trouble understanding

def mysplit (string):
quote = False
retval = []
current = ""
for char == '"':
quote = not quote
elif char == ',' and not quote;
retval.append(current)
current = ""
else:
current += char
retval.append(current)
return retval

The above code is going to step through a string, character by character, and separate components that are separated by ','. If a ' " ' is found, something happens.

I understand that a boolean value changes from False to True if a ' " ' is found, but I can't see how it's returned to False in preparation for the next parsing event.

nashyo
Aug 3, 2012, 10:33 AM
Got it...quite simple really. Used to obj C

Ap0ks
Aug 3, 2012, 11:12 AM
Hold me back!

Americans calling the hash symbol the pound symbol drives me mad. The pound symbol is "" mmmkay?Technically that's the pound sterling symbol or pound sign, a pound is a unit of weight ;)