[Tutor] how to get the return value?

Anna Ravenscroft annaraven at gmail.com
Mon Mar 6 02:05:14 CET 2006


On 3/5/06, ingo <ingoogni at cut.this.out.home.nl> wrote:
>
> in news:440B2B3E.6070407 at tds.net Kent Johnson wrote:
> >>>>[...]
> >>>
> >>>main(printtime(strf=None))
> >>>
> >>>[...]
> >>
> >> Anna,
> >>
> >> that results in an syntax error / invalid syntax
> >
> > It's very helpful to show the actual error and traceback.
> >
>
> Sorry, here it is:
>
> File "D:\Ingo\PyScript\VIDEOC~1.9\_ij\_time_lapse.py", line 23
>     def main(printtime(strf=None)):
>                       ^
> SyntaxError: invalid syntax



Yep. I was suggesting calling printtime as part of your *call* to main, not
when you define main. Sorry to be unclear.

It appeared from your code that you never bound printtime to a variable name
when you called it (in fact, I don't remember you ever actually *calling* it
but I may be misremembering.)  If it's not bound to a variable name, the
function does its work and the return value just disappears into the ether.
So - to capture the return value, bind the function call to a variable name.
Or, alternately, pass the function call directly as the argument for the
function, in your case main(), that wants to use the return value, such as:

main(printtime(strf=None))

Note that, when you define main in the first place, you'll need to ensure
that it takes a parameter like:

def main(pt):
   dosomethingwith pt

so that when you later call main(), you can pass it an argument like
primetime() or whatever variable name you bound primetime()'s return value
to.

Hope that makes more sense.

Anna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060305/b2f9e565/attachment.htm 


More information about the Tutor mailing list