Live data from Hacker News

Basic Intro to Python Metaprogramming

bitshaq.com

1–10 of 10 posts

Re: Basic Intro to Python Metaprogramming

#5
>>> 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.

Re: Basic Intro to Python Metaprogramming

#7
post #5

>>> 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.

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?

Re: Basic Intro to Python Metaprogramming

#9
post #5

>>> 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.

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?

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

Re: Basic Intro to Python Metaprogramming

#10

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.

May be this helps http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2010-pyt...