Simple Newbie Question: What am I doing wrong?

MDK mdk at mdk.com
Thu Jan 24 14:53:13 EST 2002


"Steve Holden" <sholden at holdenweb.com> wrote in message
news:iwZ38.205709$Zi2.8040536 at atlpnn01.usenetserver.com...
> "MDK" <mdk at mdk.com> wrote...
> > I have a file named mytest.py containing the following:
> >
> > def yo():
> >     print "Bla"
> >
> >
> > In the interactive window I type:
> >
> > >>> import mytest
> > >>> mytest.yo
> >
> > But I get back
> >
> > <function yo at 0x00985378>
> >
> > Why don't I get back "Bla"?
> >
> Because the expressions you typed in is a reference to the function, not a
> call of it. A call would be as follows:
>
>     mytest.yo()
>
> Remember, Python is neither Perl nor VBScript, and because it makes just
as
> much sense for program to deal with functions as it does for them to deal
> with character strings, you have to be able to both refer to and call
> functions. It's quite legal to say this:
>
>     ff = mytest.yo
>     ff()
>
> and this, too, should print "Bla".
>
> > Neither does it work if I do:
> >
> >    return "Bla"
> >
> I presume you mean that you replaced the print statement in the function
> with a return?
>
> > Why not?
> >
> For the same reason :-)
>
> regards
>  Steve
> --
> Consulting, training, speaking: http://www.holdenweb.com/
> Python Web Programming: http://pydish.holdenweb.com/pwp/
>
>

Oh! I see now.  Thank you very much.





More information about the Python-list mailing list