Python, Perl, something else?

Discussion in 'Mac Programming' started by svenr, Apr 22, 2011.

  1. macrumors regular

    Joined:
    May 6, 2003
    Messages:
    217
    #1
    I'm pretty good programming in PHP and Javascript, but now I need something that allows me to create simple desktop apps. Mostly it will be for automation scripts, too much for Apple Script, but not complex enough to jump into Cocoa and Objective-C. Examples: Manipulating text files (sorting, dupe line checking, adding/cutting parts, splitting/combining files etc.), uploading a file to several different FTP servers, sending POST requests to a server.

    I often hear Pearl and Python mentioned and I believe they are pre-installed on the Mac, but I don't know much about them. What's the main difference? Which one (or something else?) would be best suited for these tasks? Which one is easier to learn?

    Bonus: What's a good site to learn for someone who has general programming knowledge, but is a total noob with those languages?
     
  2. macrumors member

    Joined:
    Sep 15, 2008
    Messages:
    46
    #2
    I am not fluent in Perl but I do use Python at my work. I am mainly a C++ developer. I find Python easy to use and quite powerful for the things you listed. There are many 3rd party libraries that will help with most things you need to do. A SSH client called Paramiko was VERY helpful to me for logging into servers and transferring files and running commands. This site may help get you started with Python and Paramiko's SSH library.

    http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/

    As for the file and string manipulations you listed, I find just doing a google search is helpful enough.

    Just make sure you get a Python debugger if you go that way. I use Eclipse with Pydev. I am sure others may suggest a better debugger. It is adequate for my needs.
     
  3. macrumors member

    Joined:
    Sep 15, 2008
    Messages:
    46
    #3
    Given that you already know PHP and javascript, you just need help with the Python syntax. I looked up removing duplicate lines in a file on google:

    http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=python+remove+duplicate+lines+from+a+file

    I got this hit:

    http://metadeveloper.blogspot.com/2007/07/remove-duplicate-lines-in-python.html

    Or this:

    http://stackoverflow.com/questions/1215208/how-might-i-remove-duplicate-lines-from-a-file

    Try that and start building up your scripts from there.
     
  4. macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Messages:
    5,161
    Location:
    The World Inbetween
    #4
    I would use Python as there is a Cocoa bridge for Python. Though untimately you will need an understanding of Obj-C and Cocoa to make decent Mac OSX apps. Even if you are coding in Python.
     
  5. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Messages:
    1,448
    Location:
    Sydney
    #5
  6. macrumors 6502

    Joined:
    Apr 29, 2010
    Messages:
    295
    #6
    I'd use Python.
     
  7. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Messages:
    17,825
    Location:
    New England
    #7
  8. macrumors regular

    Joined:
    May 6, 2003
    Messages:
    217
    #8
    Thanks for the replies! I'm a little surprised there's not one speaking up for Perl, but yeah, did some more research on my own and found this
    http://strombergers.com/python/
    The Cocoa bridges/runtime are not a concern to me as I don't want "to make decent Mac OSX apps" with GUI and everything, just some command line tools for my own use. But the examples at that link pushed me over to go with Python. To put together quick automation scripts every now and then, I don't want to deal with a steep learning curve. The Perl examples there looked just too cryptic to me.
     
  9. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Messages:
    17,825
    Location:
    New England
    #9
    I think you've hit on one major reason why some of what might have been done done in perl ~15 years ago is likely to be done in python or maybe ruby today.

    Perl is extremely powerful, but you can do a lot of what you say you want with chains of other "single function" tools like awk, grep, sort, uniq, ....

    B
     

Share This Page