Settings

Theme

Basic Intro to Python Metaprogramming

bitshaq.com

82 points by nuclearsandwich 15 years ago · 9 comments

Reader

iandanforth 15 years ago

For me this article was written in reverse. For an intro I'd love to have had the 'code smell' example first to establish why I might care and when I might need this, and then dive into an example.

endgame 15 years ago

Can everyone please stop shoehorning in random xkcd comics where they don't belong?

  • tbh2347 15 years ago

    At the risk of introducing another level, I will mention that these comments are very Meta :)

ciupicri 15 years ago

Forbidden

You don't have permission to access /2011/07/14/basic-intro-to-python-meta-programming/ on this server.

irahul 15 years ago

>>> Foo = type("Foo", (FooBase,), {'bar' : 42})

is not equivalent to what the blog post says it is to. FooBase should be defined before running this, and the blog post's equivalent make it look like this statement defines FooBase as well.

  • jackpirate 15 years ago

    I think you neglected the line in front of it, which does define FooBase.

       1. >>> FooBase = type("FooBase", (object,), {})  
       2. >>> Foo = type("Foo", (FooBase,), {'bar' : 42})  
    
    Although I am not a python expert, so you may be right... in which case, how does line one not work?
    • irahul 15 years ago

      I stand corrected - I was skimming and didn't notice. The example is correct - I was wrong.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection