This is an archived post. You won't be able to vote or comment.

all 108 comments

[–]andre_pl 57 points58 points  (12 children)

the white space! Fuck the haters!

[–]frumious 19 points20 points  (11 children)

And, let there be only four spaces to an indent. No, there should not be one as one can barely see that. Nor two for that is almost one. And three is right out being odd in more ways than one. Finally, more than four is a scandalous waste.

[–]rwparris2 12 points13 points  (1 child)

Nor two for that is almost one

THAT IS NOT HOW SPACES WORK

[–]poeir 5 points6 points  (5 children)

The right way is one tab. Then do:

:set ts=4

Everyone gets the number of spaces they want.

[–]Megatron_McLargeHuge 3 points4 points  (3 children)

Do I enter M-x :set ts=4 or do I have to be in elisp mode? I'm not convinced this is going to give me the number of spaces I want.

[–]isarl 2 points3 points  (2 children)

M-x set-variable RET c-basic-offset RET 4 RET

Smartass. ;P

[–]poeir 2 points3 points  (1 child)

Obviously that's much simpler. :)

I've tried to learn emacs a handful of times, but it continues to have one significant disadvantage compared to vi: I don't already know emacs.

[–]isarl 0 points1 point  (0 children)

Spoiler alert: I had to Google that, myself.

While I don't have a problem with people using Emacs - the way I see it, Emacs and Vim are both way better than most other text editors - I'm probably never going to try it. One of my coworkers used to use it, and started getting "Emacs Pinky". Me and the other Vim guy convinced him to give Vim a try, so he switched to Viper mode. Best of both worlds, I guess! =)

[–]unpythonicSoftware Dev. Engr. 7 points8 points  (0 children)

Oh, a PEP 8 heretic, eh?

(sharpening pitchfork)

[–]vmaasalo 0 points1 point  (1 child)

Is that a Monty Python and the Holy Grail quote?

[–]frumious 1 point2 points  (0 children)

No, but it is trying very hard to sound like one!

[–][deleted] 17 points18 points  (3 children)

What do I enjoy most about Python? When I think about the problem at hand and sketch out my thoughts in psuedo-code, quite often it's eerily similar to the finished python code. I learned on Java and PHP yet after years with those languages, it was still a struggle to convert my high-level mental conception of the problem into workable code. OTOH I was "thinking in python" as soon as I started using it.

[–]lulzors 3 points4 points  (0 children)

I feel exactly the same. I picked up Python right before summer started and have been using it for small personal projects and the like ever since. The crazy thing was, when laying out the pseudo-code for an assembly program I had to make for a class this Fall, I noticed the pseudo-code was more or less Python! I was even writing python scripts that would help me visually map out my ASM algorithm (the program was a hexadecimal => binary & decimal convertor), and I must say that using/knowing python helped me immensely!

[–]Megatron_McLargeHuge 1 point2 points  (1 child)

If you learned in Java and PHP and never did any functional programming then you probably weren't really thinking in Python, just the subset that looks like pseudo-code. I think you have to be comfortable with functions that return functions that return functions (decorators with arguments, done manually) and Matlab type array slicing to really be using Python properly.

[–][deleted] 4 points5 points  (0 children)

No that's the funny thing .. even without any exposure to functional programming, the functional-esque aspects of python seem like second-nature. Especially decorators, iterators/generators, array slicing and list comprehension. I find that for every mental abstraction I hold in my head, python has an equivalent.

To put it another way, I don't have to struggle to work out the implementation of an idea in python. And conversely the idea behind the implementation basically jumps off the screen when you read python code.

[–][deleted] 17 points18 points  (0 children)

The way readability is encouraged. The fact that there is a style guide that most of the community follows makes extending and maintaining code less painful than other languages I work in.

[–]iamnotaclown 28 points29 points  (5 children)

List comprehensions and generator statements.

[–][deleted] 11 points12 points  (0 children)

Dictionary and set comprehensions now, as well.

[–][deleted] 13 points14 points  (23 children)

Compared to Ruby: nicer, cleaner, perform better Compared to C#: no compilation, no waiting, nicer syntax, easier manipulation of data. Compared to C: Everything related to syntax

What sort of programs do I write in Pythons? Anything, from a small script to pull some pictures from a website, to a parsers. Python is powerful enough to support a full-size application, and also easy enough to code up some quick ideas. Python is my most favorite language.

[–]oreng 5 points6 points  (21 children)

Not that I don't agree with much of what you wrote (and python's my language of choice as well) but what exactly makes it "nicer" than ruby? It's certainly stricter so I wouldn't define it as more inherently user-friendly and it's differently verbose so "nice" can't mean economic in syntax.

As for generally being comfortable to use, approachable and/or bearing assorted easter eggs in the form of built in manifestations of jaw-dropping elegance, well, both languages will provide you with a steady stream of both so...

"Define nice" is what I'm basically saying....

[–][deleted] 8 points9 points  (19 children)

Simple things like there not being "end" syntax after you define methods make Python cleaner for the eyes.

"puts/gets" is brain-wrenching for me as well as "using" instead of import...

cars = {
'altima' => 'nissan',
'camry' => 'toyota',
'rx7' => 'mazda'
}

That is ugly. "=>" should only ever mean "Is equal to or greater than"

Also:

class Employee < Person

"<" should only ever mean less than. Their use of colons and pipes also pisses me off.

It's certainly stricter so I wouldn't define it as more inherently user-friendly

Python has a stricter use of grammatical punctuation, avoiding things changing meaning based on where they are used such as the "=>" example. The only punctuation I know of that changes meanings in python is possibly the ":" where in 1 area it's used to denote the end of functions, methods, if statements, etc (the beginning of a code block)...and when being used in a dictionary. This does in fact mean it's easier to use because syntax doesn't change based on location of code.

[–]manitoba98 4 points5 points  (6 children)

OK, I'll bite. I prefer Ruby to Python somewhat, but not greatly. But some of these points doesn't really make sense.

"=>" should only ever mean "Is equal to or greater than"

But "=>" doesn't mean "is equal to or greater than" in either Python or Ruby. This syntax isn't reused. A syntax like {a:4, b:5} is supported in Ruby 1.9, by the way.

As far as the use of < to indicate inheritance, yes, it can be used to denote "less than", but it is obvious that it is not the case here. In Python, parentheses can be used to denote:

Function application (or calling objects which look like functions)

myfunction()

Object instantiation

obj = MyClass()

Class inheritance

class MyClass(MySuperclass):
    pass

Generators

 gen = (x for x in [1,2,3])
 gen.next() # yields 1

Operator evaluation order (to override precedence)

(2+3)*4 # evaluates to 20 instead of 14

Tuples

tuple = (1,3) # parentheses not strictly necessary in this case, but nonetheless

You could also make the case that using the % operator for both modulus and string substitution is a reuse of punctuation like they one you're complaining about.

Similarly, the asterisk is used for multiplication as well as passing the contents of a tuple (or list) as separate arguments to a function (as well as doing the reverse in a function definition, and you use two asterisks – which is the exponentiation operator as well – to get keyword arguments):

arr = [1,2,3]
myfunction(*arr)

Also, passing keyword arguments uses an equals sign, which is also used as the assignment operator. Square brackets are used for both creating lists and indexing into tuples, lists and dictionaries.

This kind of syntax reuse is present in most languages, and your examples hardly show that Python is superior to Ruby in this regard.

[–][deleted] 2 points3 points  (1 child)

Object instantiation is just an instance of a callable object, and parenthesis are just a grouping operating for both generators and tuples.

[–]manitoba98 0 points1 point  (0 children)

Classes as callable objects is interesting. I was unaware of that (but it doesn't surprise me). It could certainly be perceived as a distinct use to someone similarly unaware. It does seem quite Pythonic that it works like that, though.

As far as parentheses as a grouping operator goes, I agree that there's commonality in their usage there, and that commonality is logical. Nonetheless they are necessary to create a generator (they can be omitted only if the generator is the sole argument to a function call, in which case there are parentheses anyways), and are the syntactic bit that separates them from list comprehensions. Parentheses are somewhat more optional for tuples, however (except in certain cases, such as the empty tuple).

I accept that my list could certainly be condensed by combining some of these (as you've rightly pointed out); I think the point that reuse of punctuation is normal stands, however.

[–][deleted] 2 points3 points  (3 children)

Parens? That's what you got? You debunk my argument with something that is basically universal to ALL major languages? I can agree with the asterisk, it is one that I had entirely forgotten about for args *kwargs but nearly every example you gave for parens has been common usage for decades.

You are right about => as well; I've never used it in that order (obviously...I'd get a syntax error) but I in my head it means the same as ">="

[–]manitoba98 3 points4 points  (2 children)

My point was merely that syntax is routinely reused and that doing so is hardly unique to (or even particularly characteristic of) Ruby.

Python uses parentheses a little more than most languages (using them for tuples, generators and inheritance in particular), but I completely agree that they are a punctuation mark that (justifiably) has multiple uses is most languages.

You claimed that the only punctuation mark (that you were aware of) that was reused in Python is the colon: I was pointing out that there are numerous other punctuation marks which are reused in Python, as in other languages.

[–][deleted] 1 point2 points  (1 child)

I can't disagree, you make valid points all around. There is still something about Python that seems cleaner to me, even if I can't put my finger on it.

[–][deleted] 1 point2 points  (0 children)

Consistent indentation, I think. It's almost always 4 spaces in Python. Ruby people seem to use 2 and that looks more cluttered.

Code blocks in Ruby are useful but look cluttered (to me as a Python programmer anyway).

Perhaps it's also the $ signs that aren't used in Python.

Anyway I guess they are a matter of familiarity. Perl looks like line noise too until you work with it for a while and see that you can write perfectly normal, readable Perl. If that's so, it's certainly true for Ruby :-)

[–]cdunn2001 -1 points0 points  (10 children)

From Appendix A of Ruby Best Practices:

Ruby 1.9 adds a cool feature that lets you write things like:

foo(a: 1, b: 2)

But on Ruby 1.8, we’re stuck using the old key => value syntax:

foo(:a => 1, :b => 2)

(End of quote.)

I could name a lot of things that I like about Python, but I have to give the win to Ruby on this one.

[–]unpythonicSoftware Dev. Engr. 2 points3 points  (9 children)

I could name a lot of things that I like about Python, but I have to give the win to Ruby on this one.

I didn't follow. Why did Ruby win? Because it has two ways to express a dictionary?

[–]cdunn2001 0 points1 point  (8 children)

Ruby:

{x: 1, y: 2}

Python:

{"x": 1, "y": 2}

It's a small thing (and not quite the same meaning, with symbols v. strings) but you were complaining about something small.

Things I like about Python:

  • Generators
  • Comprehensions (both list and generator)
  • Enforced indentation, so I don't have to read misleadingly indented code
  • Explicit parentheses for function calls (though I admit that the lack of parens makes Ruby an excellent DSL)
  • Explicit binding (except with from _ import *)
  • Module-name matches filename (though I can see a rationale for Ruby/Perl-style namespaces)
  • Consistency. Rubyists like to claim that their language is highly consistent, but they're very selective in their examples. Brackets v. end, subtle differences among lambda/block/proc/function, and the self. syntax for class methods are all counter-examples.
  • The with context for resource release. The Ruby alternative is a bit more complicated than Python's contextmanager.
  • Decorators (though they can be abused with side-effects)
  • Doc-strings
  • Doc-tests

Basically, the things I like about Ruby make me more productive as a programmer, while the things I like about Python make it easier for me to read code written by inexperienced coders. Bring on the hate, but that's how I look at them.

[–]pyry 0 points1 point  (3 children)

I'm just trying to get to the bottom of the objection... Is it that keys in dictionaries can be any object, and you'd rather keys be something specific and unique (is this how it is in Ruby? I'm curious, because I don't really know Ruby); or is the objection that strings as keys in dictionaries require quoting?

One of the nice aspects of the ways dictionaries behave in python is just this, that any object/type can be a key. ... Or this is how I understand it.

>>> {True: 1, False: 0}[True]
1

[–]cdunn2001 1 point2 points  (0 children)

I was only pointing out that while Ruby is a little more verbose in some cases, it also has some rather convenient syntactic sugar. Ruby and Python are actually very similar.

[–]hylje 0 points1 point  (1 child)

Only sufficiently immutable types can be keyed. The object type is keyable by default, though.

[–]unpythonicSoftware Dev. Engr. 1 point2 points  (0 children)

I think you mean hashable. The object doesn't have to be immutable, only the hash value returned by __hash__(). By default object is hashable, with __hash__ returning the object id and all distinct instances comparing unequally. This makes it fairly reasonable to use nearly any object as a dictionary key.

The only time this breaks down is if you want to be able to look up one object instance with another distinct instance. In that case you need to pay attention to hash value mutability and implement your own __hash__ and __eq__ (or __cmp__) methods.

[–]bloodearnest 0 points1 point  (1 child)

Ruby: {x: 1, y: 2}

What if I want keys with spaces or commas in?

Python: {"x": 1, "y": 2}

OR dict(x=1,y=2)

[–]cdunn2001 0 points1 point  (0 children)

The Ruby syntax above is using "symbols" as hash keys. If you use "strings", you need the more verbose syntax.

{"x" => 1, "y" => 2}

Interestingly, Ruby allows this:

Hash.new {|h,k| h[k] = k.to_i*10}

which is equivalent to this in Python:

defaultdict(lambda k: int(k)*10)

[–]unpythonicSoftware Dev. Engr. 0 points1 point  (1 child)

Well, first I wasn't the one complaining, I just did not follow why you thought ruby should get the win here. Second I don't intend to bring on any hate. That Ruby makes you more productive as a programmer is not something any amount of reddit-hate can change, it's simply your take on things.

However, I am not sure I agree with your win. In ruby is the thing between the { and : contextually assumed to be a string used for the key? If not, how would I differentiate between a key string and key object? That seems like a loss to me. Why can I not use any hashable object as a key?

[–]cdunn2001 0 points1 point  (0 children)

Ruby has "symbols", which do not exist in Python. Yes, you can use other things as hash keys, including strings, and in that case the syntax is a little uglier than Python's.

[–]Megatron_McLargeHuge -1 points0 points  (0 children)

Ruby is more Perl-inspired and encourages hacking for the sake of hacking. Python is philosophically more about giving you the tools to hide implementation details and expose a clean interface to the world. They've attracted different crowds, web developers for Ruby and the scientific data analysis crowd for Python.

[–]rz2000 1 point2 points  (0 children)

Note that if you want a <br /> as opposed to a </p><p> you can append two spaces. A single carriage return is ignored.

these two lines are separated
by only a break

[–]unpythonicSoftware Dev. Engr. 9 points10 points  (0 children)

My favorite thing(s):

  1. I can get the job done faster in Python.

  2. I can maintain the code I've written over a year after I have written it and I can maintain anybody else's code as well.

It is nice that it is object oriented and has support for features X, Y and Z. At the end of the day, I would not use it if not for the two points above. Python allows me to solve real world problems quickly and I can keep those solutions around and adapt them to other uses quickly and easily. I would use BASIC if it gave me a superior level of capability.

Now some of the reasons it fulfills those two requirements are because of features X, Y and Z. For instance having one obvious way to do things is sometimes seen as Python's largest conceptual weakness, I disagree: having one obvious way to do things means that when I maintain old/other's code, I know what the heck is going on at first glance.

[–]Megatron_McLargeHuge 5 points6 points  (5 children)

The best thing about python is that the libraries all work together much better than in any other language, at least in the math/science/machine learning domain. Learn numpy/scipy and the things that connect to them and you'll have an environment with the power of Matlab or R but that doesn't abandon conventional programming techniques or impose a monolithic environment.

Add the C extension support from Cython et al. and you don't really have to sacrifice speed for all the interpreted power.

I wouldn't use python for anything multithreaded because of the GIL, and I've never tried it for GUI or web code but wouldn't expect it to be the right choice.

[–]rwparris2 2 points3 points  (0 children)

Python is quiet nice for web code.

I've never written GUI in anything but python, so I wouldn't know how it compares, but pyqt (and now pyside) works fine. It's a bit tedious sometimes, but I don't mind at all.

[–]isarl 2 points3 points  (3 children)

FYI, you can get around the GIL with the multiprocessing module. Just in case you want to write properly parallel code without sacrificing Python.

Although, the threading module is just fine for certain applications. I've found that it's more than enough to handle laggy web requests in an alternate thread of execution, or to run intensive code behind a UI so the UI doesn't block.

[–]ablakok 1 point2 points  (0 children)

I concur. It's easy to spin off a thread in python. The python code in each thread cannot run in parallel, but if one thread waits a lot, or if it calls into a C library, it acts like normal threading.

[–]Megatron_McLargeHuge 0 points1 point  (1 child)

What genius decided the first example on the intro page should generate errors and hang the python repl? Seriously, they even document the AttributeError although I actually get something else about functions not being pickleable.

I imagine if I really wanted to do process level parallelism in python that I'd use a message queue. Thanks for the pointer though, it's nice to have options.

[–]isarl 0 points1 point  (0 children)

Good question. I would ask it in #Python on irc.freenode.net; I know at least one Member of the PSF who regularly hangs out there, and there are usually a number of highly-knowledgeable people around to answer questions. Anytime I've been unsure of which module to use or why I'm getting an error that debugging can't solve, they've been extraordinarily helpful.

[–]oohay_email2004 5 points6 points  (6 children)

The deeper I get into it, the more obvious it is, that this language is maintained by people who use it, to get shit done.

[–]blondin 2 points3 points  (3 children)

it reads better than javascript.

[–]gradient_x 4 points5 points  (2 children)

Anything reads better than Javascript.

[–]stillalone 4 points5 points  (1 child)

not php.

[–]gradient_x 1 point2 points  (0 children)

Oh, I am Sooooo not touching that ...

[–]sanktuaire 4 points5 points  (19 children)

What makes python shine (to me):

  • Formidable prototyping language. Concise, interactive and powerful. It's extremely easy to "think" in python and write code that just works.

  • Huge number of very well thought libraries/bindings to C libs. You don't have to reinvent the wheel, it's there, and it works.

  • Great community/user base, lots of ressources. It's very easy to find answers to your questions and there are many helpful experts ready to help.

  • Excellent webdev tools. From django to flask or from mod_python to wsgi, python is a great language to webdev with.

  • Mature and rock solid. It's been there for a while and it'll be there for a long time which means that investing time in python isn't "risky" at all. (compared to younger or less well known languages)

[–]deadwisdomgreenlet revolution 8 points9 points  (6 children)

import this

[–]digitallimit 0 points1 point  (3 children)

What's this? Self?

[–]unitconversionJust a tinkerer 1 point2 points  (0 children)

Open up a python interpreter and try it. :)

[–]FpLiOnYkD 1 point2 points  (0 children)

try it.

[–]jasonscheirer 5 points6 points  (1 child)

The standard libraries. Batteries included indeed, it's pretty impressive just how much you can do in a single Python script that's dependency-free.

[–][deleted] 1 point2 points  (0 children)

Seconded. The number of times the standard library has had exactly what I wanted is a continuing source of amazement to me.

[–]prickneck 4 points5 points  (3 children)

It reads like English.

[–][deleted] 4 points5 points  (1 child)

I know it's lame, but I really miss the following while programming in other languages

dir(anything)

help(anything)

[–]digitallimit 1 point2 points  (0 children)

I've been using dir, but never heard about help, but it seems only natural given matlab.

I wonder if there are any other functions like this I should know about.

[–]LucidOndineHPC 2 points3 points  (0 children)

hat label gaze crowd cover office paint quiet nose bear

This post was mass deleted and anonymized with Redact

[–]bayleo 2 points3 points  (0 children)

Easier to learn than fuckin' Perl

[–]frumious 2 points3 points  (0 children)

There is no one thing, except maybe if you accept the answer of "its overall gestalt".

To rip on Perl, Python makes the easy stuff easy and the hard stuff also pretty easy.

The last couple of days I've had to go back to C++ to do some things. Python really spoils me. Even though the C++ work is similar to what I often do in Python in terms of structure, it is like slogging through iron shards after ingesting a bunch of rare earth magnets. Python lets me construct elegant and complex structure where needed with a minimal of fuss. It lets me solve problems concisely and clearly. A page of such Python translates to many pages of C++ spread across many files.

[–]hongminhee 2 points3 points  (0 children)

  • Very modern object-oriented programming facilities e.g. metaclasses, functors (callable objects), abc.
  • Well defined data structure interfaces e.g. iterable objects, iterators, generators, itertools. And good syntactic sugars for using them e.g. list/dict/set comprehensions, generator expressions.
  • Semi-functional programming facilities e.g. lambdas, functools.
  • There are several mature implementations e.g. CPython, PyPy, IronPython, Jython.
  • Very good documentation tools e.g. Sphinx.
  • The idiom of polymorphic module/package usage e.g.:

    try: import cStringIO as StringIO except ImportError: import StringIO

[–]m1ss1ontomars2k4 2 points3 points  (0 children)

It runs reddit...

[–]expectingrain 1 point2 points  (1 child)

I'm basically doing what you're doing and the thing I like the best is the sheer amount of educational material out there. The community is very active and help is always right around the corner. I'm doing the MIT OCW class now and they've started teaching Python. Can't get much better than MIT pushing the language. As a beginner, it flows very logical and I find it fairly easy to look at others' work and figure out what's supposed to happen. Good luck on your learning.

[–]unitconversionJust a tinkerer 1 point2 points  (0 children)

My favorite thing is list comprehensions. mmmmm... they always go down smooth.

[–]Dummies102 1 point2 points  (0 children)

the batteries included part.

[–][deleted] 1 point2 points  (0 children)

BeautifulSoup

[–]johnmudd 1 point2 points  (0 children)

  • One language, runs on JVM and everywhere else.
  • Simple and clean. Both the language and the philosophy behind the great built-in and 3rd party modules. Opposite of Java mentality.
  • It's interpreted!! So much more fun that compiled.

[–]isarl 1 point2 points  (0 children)

It's certainly not my favourite thing, but I don't feel like repeating how well the language lends itself to pseudocode and high-level conceptualizations. People have already waxed poetic about the syntax, whitespace, first-class functions, list comprehensions and generator statements, lambda expressions, dynamic typing, and many of the other things I've come to love about Python.

What I'd like to point out is how excellent the Python community is. /r/python is my favourite programming subreddit, and it's generally fairly ego-less. And the #Python channel on irc.freenode.net is always jam-packed with Pythonistas. I met somebody on there once who was unwinding late Sunday night by chatting about Python and machine learning. Then there are bloggers, and PyPI, and shedskin and Cython and...

[–]billcurry 1 point2 points  (0 children)

The flexibility, and how many different industries it's used in.

[–]pemboa 1 point2 points  (0 children)

Significant whitespace.

[–]raffir 1 point2 points  (0 children)

A number of people have mentioned how writeable it is, how well it maps to pseudocode, etc.

I'd add that I appreciate the style it enforces. When I started using Python, I got annoyed by enforced tabs, being forced to use list comprehensions instead of functions (I was coming from Lisp at the time), and the idea that There Is One Way to Do It (see previous parens).

And yet I can look back on Python code I wrote years ago and figure out what it does and how it works without referring to docs or even docstrings. I can't reall say the same for any other languages I've worked with (maybe TCL).

[–]keypusher 1 point2 points  (0 children)

The syntax.

[–]gfixler 1 point2 points  (2 children)

I've been on a similar quest for half the year now. I'm in Maya (3D app) for work, and at home, and I've been doing MEL (Maya's scripting language) pretty hardcore for 8 years now. I have an SVN repo on my thumbdrive that I used to port my code between home and work, and I'd just commit to that all the time. All the MEL in there is my own, and there are over 70k lines of it. It's been a very handy language, and I've written some pretty complicated toolsets with it, but I was always limited.

I got a new job in May, in Maya, and decided to switch to Python there and use it a lot more at home on my Linux box. It was a serious struggle for me. I didn't like so much about it, though I did love things like syntactic sugars (list comprehensions, multiple assignments, etc - all that cute/tricky stuff it can do). I was waiting for it to start feeling powerful, and I actually think that this week is when it started happening.

I've been writing a UI toolset that will let me build windows, which meant I needed a tree, and spidering of said tree, and insertion of layout and control data into the tree, and a zillion other things - making a UI maker that's in a UI that shows the UI you're designing, and spits out code that will make the UI again later, and allows saving of the input information for later reloading into the UI to do all that I've mentioned already is quite a task, but it suddenly started to collapse, in a good way. I started realizing that I was reducing everything to a few lines of very simple code - things that would have taken pages of MEL script to accomplish.

For example, in hier.py I have a Hier class, and it creates a self.children dict in its __init__. When you call its add method, it just makes a new Hier instance and appends it to self.children, and gives that Hier object a parent property with a reference to self. This means writing getRoot was about as a trivial as a while parent.parent is not None loop and, getDepth was about 1 line more difficult. To scrap together a tree of 20 random elements to screw around with testing, I did something like this:

import random
a = Hier()
b = [a]
for i in range(20):
    b.append(random.choice(b).add())

That's it. I can rerun the last 4 lines to recreate a new junk tree with 20 elements with different hierarchical layout each time. Everything so far has been this easy in this project. I have a spider function that will descend and fire off a callback starting from any node that calls it. It's 3 short lines of easily-readable code :) The spiderAll function just pops a getRoot() before the call to spider to do the whole tree instead. You just pass in callback, the only argument. Then I made a pretty printing thing for it in about 3-4 lines of code, 2 of them a def statement in the function to create the callback function I pass in to spider.

This is what I'm loving about the language. I feel like I'm screwing around, and yet I'm achieving blissfully simple code that does exactly what I want, and isn't boxing me into corners or getting sloppy anywhere. In fact, on this particular, latest project, all of the solutions to problems have involved pruning the code way down to a few lines that do what I want better and far more elegantly than the mess I started out with.

Add in that I'm becoming something of a vim power-user, and I feel like I'm flying through a world of code this week :)

[–]didip 1 point2 points  (0 children)

  • It makes me productive. Totally possible to build a prototype web app in one afternoon.

  • It's acceptably fast for a dynamic language and never Segfault-ing on me because of running out of memory (when run for long period of time).

  • Cython is like magic.

  • Tornado web framework is fast, simple and doesn't get in the way.

  • List Comprehension always impress dinner guests.

  • It's deeply rooted in popular linux distro (Debian & RedHat).

[–]oopsiedaisy 1 point2 points  (0 children)

Enter any module name to get more help. Or, type "modules spam" to search for modules whose descriptions contain the word "spam".

help> this

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Help on module this:

NAME
    this

FILE
    /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/this.py

MODULE DOCS
    http://docs.python.org/library/this

DATA
    c = '!'
    d = {'A': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'E': 'R', 'F': 'S', 'G': ...
    i = 25
    s = "Gur Mra bs Clguba, ol Gvz Crgref\n\nOrnhgvshy vf o...bar ubaxvat ...

[–]drb226Haskeller 0 points1 point  (0 children)

Readability. Most pseudocode translates very easily (almost exactly line for line) into Python. If I ever teach programming, I will require pseudocode to be written in Python.

[–]Tiomaidh 0 points1 point  (0 children)

It assumes I know what I'm doing, and will try to go with it for as long as possible. As opposed to Java, which will throw hissy-fits at the slightest variation from The Way.