Closures in leu of pointers?

alex23 wuwei23 at gmail.com
Mon Jul 1 00:57:20 EDT 2013


On 30/06/2013 3:46 PM, Ian Kelly wrote:
> In general I agree, although when reading code I would definitely
> prefer if the locals were declared.

If you import the code into the interpreter as an adjunct to reading it
you can see the locals with:

 >>> somefunc.func_code.co_varnames # 2.x
 >>> somefunc.__code__.co_varnames  # 3.x

> On a related note, I think that generator functions should in some way
> be explicitly marked as such in the declaration, rather than needing
> to scan the entire function body for a yield statement to determine
> whether it's a generator or not.

 >>> inspect.isgenerator(somefunc)

However, a dedicated code reader built around the inspect module could
be a handy tool.




More information about the Python-list mailing list