Better HN
topnewbestaskshowjobs
Log inSign up

webexcess

363 karma · joined Feb 17, 2011 (15y ago) · 13 submissions

Submissions

comment 13y ago · link · parent

Yes, your code is the same as the first example generator with a single yield in a loop.

The same conversion for the later examples with multiple yield statements, try: except: or try: finally: will be much hairier, though.

comment 13y ago · link · parent

I stole that from here http://meyerweb.com/eric/css/edge/complexspiral/glassy.html

comment 13y ago · link · parent

Thank you, I hadn't seen that. I've added that link to the bottom of my article.

comment 13y ago · link · parent

That's a feature!

Seriously though, not being able to define a serialization method can be a limitation. However, it is always possible to turn a generator into an iterator class with whatever methods you like, but the code may end up looking totally different.

5.

Python Generators in Depth(excess.org ↗)

171 points · by webexcess · 13y ago · 26 comments

6.

Python Iterables, Iterators and Generators (part 1)(excess.org ↗)

2 points · by webexcess · 13y ago · discuss

comment 14y ago · link · parent

It should be possible to create the exact same classes dynamically, without using exec. The only advantage I can see of the exec is that the class template string makes it a little clearer what the equivalent "normal" class definition would look like.

There are other drawbacks to exec though, some people have disabled exec for security reasons and it's opaque to things like pypy.

comment 14y ago · link · parent

You can use python -i to enter interactive mode after executing a script. Maybe I should clarify that part

comment 14y ago · link · parent

Good point. I didn't address this adequately.

The usual #python response to people using the array module was to instead consider NumPy (with its excellent arrays) or use normal lists and PyPy to make it fast.

10.

Unfortunate Python(excess.org ↗)

194 points · by webexcess · 14y ago · 55 comments

11.

Urwid 1.0: python 3 support, terminal widget, pop-ups, tree views and more(excess.org ↗)

2 points · by webexcess · 15y ago · discuss

12.

Django Widgets, Form Fields and Model Fields Explained(excess.org ↗)

2 points · by webexcess · 15y ago · discuss

13.

Moving to Python 3(lwn.net ↗)

2 points · by webexcess · 15y ago · discuss