how python dir works

Ian Kelly ian.g.kelly at gmail.com
Wed Apr 18 12:15:51 EDT 2012


On Wed, Apr 18, 2012 at 9:56 AM, cheung <mwpcheung at gmail.com> wrote:
> how does the function  "dir" works, where can I get the python-c  source of dir in py2.7 project.
>
> I looked the python_c source for hours, can't find how dir works.

http://hg.python.org/cpython/file/67be12ab8948/Objects/object.c#l1957

> for example:
>   if a user input a *.py source file like foo.py, i wanna parse the file, and find all the functions and all the classes in the foo.py.

Without actually executing the file?  Then you should probably forget
about dir() and use the ast module for parsing.

Cheers,
Ian



More information about the Python-list mailing list