> This is more a Python issue than a Django one, but I thought the
> Python-aware people that you are might be able to help me :)
>
> I would like to do something like:
>
> def called(arg)
>    if arg==True:
>        !!magic!!caller.return 1
>
> def caller(arg)
>    called(arg)
>    return 2
>
> Here, the fake !!!magic!!! represents a statement (which I ignore)
> that would make the caller function return a value different from what
> it'd return normally.
>
> For example, caller(True) would return 1, and caller(False) would
> return 2. The reason I want that is because I don't want the caller
> function to know what's going on in the called function, and be
> shortcut if the called function think it's necessary.
>
> Would you know if that's possible, and if so, how?

What is wrong with:

def called(arg):
   if arg == True:
     return True
   .
   .
   return False

def caller(arg)
   if called(arg):
     return 1
   return 2

If you like different return values, something like:
     return (True, <other values>)
in called() and
   shortcut, <return values> = called(arg)
   if shortcut:
     return <return values>
in caller() works for me.

As Malcolm mentioned, throwing an exception might be another good way  
to do things.
Or did I miss the point of what you're trying to do?


> I've done a bit of research and I think I've found some good pointers,
> in particular using the 'inspect' library:
>
> import inspect
>
> def called(arg)
>    if arg==True:
>        caller_frame = inspect.stack()[1]
>        ...
>
> Here 'caller_frame' contains the frame of the caller function. Now,
> how can I make that frame return a particular value?
>
> Hope that was clear... :/
>
> Thanks!
>
> Julien
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to