Simple Newbie Question: What am I doing wrong?

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Thu Jan 24 14:44:22 EST 2002


"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"?
>
>Neither does it work if I do:
>
>   return "Bla"
>
>Why not?
>
>Thank you for your help.
>
>

See if I can get in first with the answer.

You're not calling the function unless you put () on the end.

So you need:

mytest.yo()

Otherwise you're just referencing the function. This is comon in a few
languages I can think of.

Why would you want to reference the function?

Consider:

func = mytest.yo
.
.
func()


Would also execute your function. Passing functions around is quite
handy sometimes.


--
Dale Strickland-Clark
Riverhall Systems Ltd



More information about the Python-list mailing list