Author Topic: Python  (Read 6216 times)

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Python
« Reply #15 on: April 13, 2008, 01:28:56 AM »
instead of "while x < names.length:" you can use "for name in names:"... one those python niceisms.

That was how my code originally was, but then to get the same output, I would have to use:
Code: [Select]
x = 0
for name in names:
    print name.childNodes[0].nodeValue, ":", text[x].childNodes[0].nodeValue
    x+=1

And not only is that ugly, but it creates a bunch of extra objects to boot. Although I'm not 100% on how Python does everything behind the scenes, so maybe not.

But how is that better than what I've done?

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Python
« Reply #16 on: April 13, 2008, 09:48:26 AM »
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.

nope. just the indentation. The function ends when the next line starts with no indent. (and with "def funtion()"):

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Python
« Reply #17 on: April 13, 2008, 11:36:41 AM »
So say you had

Code: [Select]
def foo()
statement 1
statement 2
statement 3
statement 4
statement 5

statement 6
statement 7
statement 8
statement 9
Would the function end after #9 or #5?

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Python
« Reply #18 on: April 13, 2008, 11:54:48 AM »
after 9

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: Python
« Reply #19 on: April 13, 2008, 11:56:22 AM »
>But how is that better than what I've done?

it's not better, its just one of those syntactic conveniences. I'm pretty sure python will just bind name to a pointer and iterate it, i don't think it will actually create an object.

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Python
« Reply #20 on: April 13, 2008, 12:26:54 PM »
Yeah, it's not completely whitespace-sensitive, just indenting.

But in any case, for my own personal reference, could someone please explain why that was crappy Python coding? If there's a more python-y way to do it, I wanna learn!

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Python
« Reply #21 on: April 13, 2008, 01:37:15 PM »
Ok thanks, so it isn't as bad as it seemed.

Can't say I'm thrilled with the indentation scoping thing though.  Over at SMF we've been fighting someone's editor magically inserting spaces at the beginning of lines, between tabs, etc.  In PHP that isn't a problem but in Python that would just wreck havoc.

-KEN-

  • Some Other Mofo
  • Jackass In Charge
  • Posts: 1001
  • Karma: +75/-100
Re: Python
« Reply #22 on: April 13, 2008, 07:10:17 PM »
Right, I can't imagine sharing some python source across programmers with different environments and OSes.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: Python
« Reply #23 on: April 22, 2008, 09:44:20 AM »
another from xkcd.... the payoff is at the end

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

VBprogrammer

  • Back on GMT thank god
  • Jackass IV
  • Posts: 747
  • Karma: +13/-21
Re: Python
« Reply #24 on: April 24, 2008, 08:50:23 PM »
I'm starting to wonder if the XKCD guy is taking the piss re Python :)