Learning Python

Discussion in 'Mac Programming' started by nashyo, Aug 2, 2012.

  1. macrumors 6502

    nashyo

    #1
    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?
     
  2. macrumors 603

    Cromulent

    #2
    Here you go.

    1. Open Terminal
    2. Type nano test.py
    3. Add code and save it
    4. Close nano
    5. Type "python test.py" (without the quotes) and press return
    6. See the results of your program
    7. 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.
     
  3. Moderator

    balamw

    Staff Member

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

    B
     
  4. Fed
    macrumors 6502

    #4
    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.
     
  5. macrumors member

    #5
  6. macrumors member

    #6
    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.
     
  7. macrumors 603

    thekev

    #7
    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.



     
  8. macrumors 6502

    nashyo

    #8
    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?
     
  9. Ap0ks, Aug 3, 2012
    Last edited: Aug 3, 2012

    macrumors regular

    #9
  10. macrumors 6502

    philosopherdog

    #10
    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.
     
  11. macrumors 6502

    nashyo

    #11
    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
     
  12. macrumors member

    #12
    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/
     
  13. macrumors 603

    Cromulent

    #13
    Hold me back!

    Americans calling the hash symbol the pound symbol drives me mad. The pound symbol is "£" mmmkay?
     
  14. macrumors 603

    thekev

    #14
    That author is just completely awesome.
     
  15. macrumors 6502

    nashyo

    #15
    Having trouble understanding

    Code:
    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.
     
  16. macrumors 6502

    nashyo

    #16
    Got it...quite simple really. Used to obj C
     
  17. macrumors regular

    #17
    Technically that's the pound sterling symbol or pound sign, a pound is a unit of weight ;)
     

Share This Page