Author Topic: Python  (Read 6211 times)

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Python
« on: April 11, 2008, 12:26:33 AM »
Anyone ever use it? I'm just starting to learn it, and so far, I really like it. Right now the language sort've reminds me of a more OOP Perl (which I have to admit, I love). Perl was cool because syntactically, it's similar enough to weakly-typed C where I was more-or-less comfortable writing whatever and checking the syntax and functions as I went, and it let me focus more on getting stuff done than the nitty-gritty memory and variable details (you can decide whether that's a good or bad thing).

Python's a bit different, but still seems like it could feel like home one day. There seems to be a decent amount of hype around it lately (at least in the journalism industry, if you've ever heard of Django), although I know it's not exactly a new language.

My only gripe so far is that, instead of curly brackets indicating scope, a la "myfunction() { /*stuff*/ }", it uses indenting, meaning I'd have to write that short function/if statement/loop as

def myfunction():
    #stuff
    #more stuff
    if blah:
        #more stuff

Which I guess is nice for readability, but did make me aware of my VIM settings using large tabstops instead of individual spaces (which I've now fixed). And plus, I think there's something to be said for an insane single line of code.
 
In any case, your guys' thoughts?

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Python
« Reply #1 on: April 11, 2008, 12:32:05 AM »
Oh, and the __blah__() syntax of certain special functions kills me. Especially when you're extending to __blah____subblah() at points -- I can't remember where I saw that, somewhere in Django, and it made me very sad. I think it's because you can't do __blah__.subblah() in whatever case that is, but don't quote me on that, because I'm probably very wrong.

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Python
« Reply #2 on: April 11, 2008, 01:35:47 AM »
Holy shit this is hilarious

charlie

  • Jackass In Charge
  • Posts: 7896
  • Karma: +84/-53
Re: Python
« Reply #3 on: April 11, 2008, 11:11:09 AM »
I've looked at python a little bit and I'm intrigued. I've also heard lots of good things about it. Unfortunately I just don't have time or reason to do anything with it.

Maybe some day.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Python
« Reply #4 on: April 11, 2008, 11:50:22 AM »
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Python
« Reply #5 on: April 11, 2008, 12:28:02 PM »
I love python, it's without a doubt the most programmer friendly language out there.

it doesn't scale well to large numbers of objects though in memory (like, GBs), watch out!

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Python
« Reply #6 on: April 11, 2008, 12:29:38 PM »
>My only gripe so far is that, instead of curly brackets indicating scope

That can be a pain if your code gets messed up and you need to re-indent. On the other hand everyones code looks the same, you don't have to deal with these types of style issues.

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Python
« Reply #7 on: April 11, 2008, 01:37:26 PM »
Sorry but languages need to be whitespace insensitive.  For example when I write classes that have a get accesser member function it is generally done on one line:  int foo() { return bar; }
It is short and sweet.

While I'm not adverse to learning it I think there are other languages that would serve me better.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: Python
« Reply #8 on: April 11, 2008, 01:44:59 PM »
I looked a bit at python a while ago when I was messing with Blender but I didn't get too excited about it. It just did things a little bit weird for me.
I know it's big inside Google, but I've found more interest in Groovy lately for me quick and dirty programming.
There's just too many languages out there these days.
This signature intentionally left blank.

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Python
« Reply #9 on: April 11, 2008, 02:45:30 PM »
I once had a prof who called python "Perl for humans".

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Python
« Reply #10 on: April 11, 2008, 08:45:30 PM »
I just love that this is all it takes to parse an XML file:
Code: [Select]
#!/usr/bin/python
#Parse the Twitter friends RSS feed to get the pertinent data
import sys
from xml.dom import minidom
doc = minidom.parse(sys.argv[1])

#Get all doc elements matiching a given tag
names = doc.getElementsByTagName("name") #Get all <status> tags
text = doc.getElementsByTagName("text") #get all <text> tags

x = 0
while x < names.length:
    print names[x].childNodes[0].nodeValue, ":", text[x].childNodes[0].nodeValue
    x+=1

Although, after writing my crime map's XML parsing routines in javascript, they seem fairly similar:

Code: [Select]
//snip...
    var type = xml.getElementsByTagName("type");
    var text;
   
    for (var i = 0; i < addrs.length; i++) {
        if(type[i].firstChild.nodeValue == "Incident") {
text = "<b>" + type[i].firstChild.nodeValue + //...

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Python
« Reply #11 on: April 12, 2008, 12:18:25 PM »
instead of "while x < names.length:" you can use "for name in names:"... one those python niceisms.

VBprogrammer

  • Back on GMT thank god
  • Jackass IV
  • Posts: 747
  • Karma: +13/-21
Re: Python
« Reply #12 on: April 12, 2008, 12:35:02 PM »
Sorry but languages need to be whitespace insensitive.  For example when I write classes that have a get accesser member function it is generally done on one line:  int foo() { return bar; }

Your missing the point. In Python you will pretty much never have to write a line of boiler plate code like that.

I would actually say one of my favorite parts of Python is the lack of parenthesis matching!

And Yeah -KEN-, that was a horrible example of Python coding!   

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Python
« Reply #13 on: April 12, 2008, 11:30:13 PM »
You are missing the point:  I WANT to be able to do that if I so choose.  The language is my bitch not the other way around.

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Python
« Reply #14 on: April 12, 2008, 11:31:31 PM »
Also from looking at some code examples it appears as though a blank line ends a function.  This isn't cool as I tend to put blank lines in my functions to help logically group statements.