[Tutor] Converting code to string

Kent Johnson kent37 at tds.net
Thu Aug 23 22:52:23 CEST 2007


Bernard Lebel wrote:
> Hello,
> 
> I'm looking for a way to convert Python code into a string.
> 
> For example, let say I have this function:
> 
> def myFunc():
>     print 'hello world'
> 
> 
> Now in the same module, I'd like to take this function and convert it
> into a string:
> 
> """def myFunc():
>     print 'hello world'\n"""

Try inspect.getsource(myFunc). But why?

Kent


More information about the Tutor mailing list