[Tutor] Local vs global
bibi midi
bibsmendez at gmail.com
Mon Nov 9 06:03:08 CET 2009
On Sun, Nov 8, 2009 at 8:38 AM, Dave Angel <davea at ieee.org> wrote:
>
> You have the following line at top-level:
>
> if ask.lower not in reply:
>
> But you're not calling the method str.lower(), you're just creating a
> function object from it. You need those parentheses.
>
> if ask.lower() not in reply:
>
>
> You have the following fragment in main():
>
> print(intro)
> choose_Cave()
> ans = choose_Cave # use: pass function by reference
> checkCave(ans)
>
>
> which has two references to choose_Cave(). The first one calls it, but
> throws away the return value. The second does not call it at all, but
> merely creates a function object and stores it in ans. You need to
combine
> your two intents in one line:
>
> print(intro)
> ans = choose_Cave() # use: pass function by reference
> checkCave(ans)
>
> Hope that helps. Remember, that unlike Pascal, in Python you don't call
the
> function unless you include the parentheses.
Hi Dave and all,
My eyes failed me spotting the bugs :-) They are just staring at me
yet i miss to catch them. I guess thats the net result when one take
it too seriously haha (joke).
I fully agree function is not called when the parenthesis is missing,
you only call the object. About Pascal or VB i cant comment on them
:-)
The code works as expected now. I guess i have to move on to the other
examples.
Will be back here to bug you guys with questions :-) Thank you for so
helpful.
--
Best Regards
Jonathan Swift - "May you live every day of your life." -
http://www.brainyquote.com/quotes/authors/j/jonathan_swift.html
--
Best Regards,
bibimidi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091109/2ff4031c/attachment.htm>
More information about the Tutor
mailing list