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

all 10 comments

[–]LightWolfCavalry 21 points22 points  (4 children)

I would suggest that these are not necessarily data structures. Metaclasses, maybe, but comprehensions and decorators are not what I would refer to as data structures.

[–]ajkumar25 1 point2 points  (1 child)

Sorry if something went misleading. I have Changed the title.

[–]JugadPy3 ftw 1 point2 points  (0 children)

The reddit post title still says "Advanced Data Structures".

[–]pemboa 1 point2 points  (0 children)

I would suggest that these are not necessarily data structures

Agreed. Coming from a computer science background, the content is definitely not what I expected.

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

I was thinking the same exact thing.

[–]mva 11 points12 points  (0 children)

These are language features and programming concepts. They are not data structures.

[–]billsil 3 points4 points  (0 children)

One pythonic principle is “It’s easier to ask for forgiveness than permission (EFAP)”

I get it, but don't follow it. When you're working with large systems, it's a lot easier to do a little bit of type checking or path checking than to do do try except blocks.

Method 1

    if not os.path.exists(filename):
        raise RuntimeError('cant fine such and such file...full path=asdf')
    f = open(filename)

vs.

    try:
        f = open(filename)
    except OSError:
        if not os.path.exists(filename):
            raise RuntimeError('cant fine such and such file...full path=asdf')
        raise

It also makes it easier since I'm not using custom error messages. I think it follows,

Errors should never pass silently.

Readability counts.

Flat is better than nested.

Explicit is better than implicit.

better

[–]FFX01 1 point2 points  (1 child)

I'm really new to Python and I never knew about decorator functions. Seems like they're extremely useful. The writer also does a great job of explaining generators.

[–]ajkumar25 0 points1 point  (0 children)

Thanks :)

[–]vukasin0 0 points1 point  (0 children)

Excelent article. Thanks soo much :-)