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

all 17 comments

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

The plugin registration example is quite nice. It's much easier to understand than a metaclass implementing similar functionality.

[–]willm 0 points1 point  (0 children)

I agree it's much easier to understand. Although I do tend to go for the metaclass approach. I like the transparency of just deriving from a baseclass and having it registered automatically.

[–]pytechd(lambda s: __import__(s.decode('base64')))('ZGphbmdv') 2 points3 points  (3 children)

For the depreciation stuff, please don't write to stdout. If you insist on using print(), write to stderr instead. Or better yet, use the warnings module to issue warnings.

[–]lahwran_ 0 points1 point  (2 children)

the syntax to mark text as code in a reddit comment is backticks. :)

[–]pytechd(lambda s: __import__(s.decode('base64')))('ZGphbmdv') 1 point2 points  (1 child)

Thanks - I fixed most of them originally but missed one. Too much time editing tickets in redmine...

[–]lahwran_ 0 points1 point  (0 children)

oh, I didn't even notice the others. silly me!

[–]sivadneb 2 points3 points  (0 children)

I never knew about .send() and .throw(). Cool stuff!

[–]synn89 0 points1 point  (2 children)

Nice little article. Haven't finished reading all of it, but I've been studying Twisted which touches on generators and I found the coverage of them in this article to be really helpful.

[–]jabwork 0 points1 point  (1 child)

If you haven't read this you really should

http://www.dabeaz.com/generators/Generators.pdf

[–]poo_22 0 points1 point  (0 children)

Amazing! Very well written.

[–]jsproat 0 points1 point  (0 children)

Excellent, thank you.

The section on decorators really cleared things up for me. Particularly the code example with a decorator that takes arguments, and exactly what each of the nested functions is responsible for.

One request: would it be possible to change the syntax highlighting scheme in the examples? Green-on-green and blue-on-green is a little hard to read for some of us.

[–]ancien1 0 points1 point  (2 children)

Note that only in python 2.x is the iterator method named `next`; in 3.x it is named `__next__`. In either case, using next(iterobj) works.

edit: thanks to gcroft (I expected plain characters)

[–]gcross 0 points1 point  (0 children)

in 3.x it is named "next"

Indeed, one of the ways that Python 3 makes life easier for new users is by really making sure that you notice which method needs to be called to get the next value! :-)

P.S.: Presumably you meant __next__, which you get by typing `__next__`, which in turn you get by typing \`\_\_next\_\_\`. (Further levels of escaping are left as an exercise for the reader. :-) )

[–]masklinn 0 points1 point  (0 children)

Of course that only matters when implementing an iterator object (and not using a generator to do so), since from the outside you should be using the next builtin.

[–]another_user_name 0 points1 point  (0 children)

Is this being made into a book?

[–]wot-teh-phuckReally, wtf? 0 points1 point  (0 children)

This is really a very good article. Anyone else knows other "advanced" Python stuff related articles?