[Tutor] repr()

Bernard Lebel 3dbernard at gmail.com
Tue Jun 7 22:42:05 CEST 2005


Ok thanks a lot.

The real question is, then, is there a way I can print the code of a
function as a string? Something like....

'def myFunction: print "hello"'


Thanks
Bernard



On 6/7/05, Max Noel <maxnoel_fr at yahoo.fr> wrote:
> 
> On Jun 7, 2005, at 20:42, Bernard Lebel wrote:
> 
> > repr( myFunc )
> >
> > Wich returns
> >
> > '<function myFunc at 0x009C6630>'
> >
> >
> > Okay then I run
> >
> > s = repr( myFunc() )
> > print s
> >
> > Wich returns
> >
> > 'None'
> 
>      That's perfectly normal. Your last assignment calls the
> function, then assigns to s the representation of the function's
> return value. A function that doesn't have a return statement returns
> None, and repr(None) == 'None'. Which is what you get.
> 
> -- Max
> maxnoel_fr at yahoo dot fr -- ICQ #85274019
> "Look at you hacker... A pathetic creature of meat and bone, panting
> and sweating as you run through my corridors... How can you challenge
> a perfect, immortal machine?"
> 
>


More information about the Tutor mailing list