[IronPython] Get Methods and variables out of a python script from C#

Michael Foord fuzzyman at voidspace.org.uk
Thu Sep 24 18:32:07 CEST 2009


Eichhorn, Georg wrote:
>
> Hi,
>
>  
>
> I want to write a little "Parser" that gets out all functions and 
> variables out of a python script. It also would be nice to have the 
> line numbers of the function.
>
> I don"t want to run the script(s), I only want to parse them. Is this 
> possible? and how?
>

It should be possible using the IronPython parser / tokenizer.

Here's an example of using the tokenizer to do colorizing of source 
code. It should be easy to adapt to pull out names used 
(TokenCategory.Identifier), not sure about line numbers but it should be 
easy to experiment to see what information is available:

http://code.google.com/p/trypython/source/browse/trunk/trypython/app/colorizer.py

All the best,

Michael Foord



>  
>
> Thanks in advance,
>
> Georg Eichhorn
>
>
> ------------------------------------------------------------------------
> The information contained in this message may be confidential and 
> legally protected under applicable law. The message is intended solely 
> for the addressee(s). If you are not the intended recipient, you are 
> hereby notified that any use, forwarding, dissemination, or 
> reproduction of this message is strictly prohibited and may be 
> unlawful. If you are not the intended recipient, please contact the 
> sender by return e-mail and destroy all copies of the original message.
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/




More information about the Ironpython-users mailing list