getting name of passed reference
Tim Roberts
timr at probo.com
Thu Dec 31 00:48:56 EST 2009
Joel Davis <callmeclaudius at gmail.com> wrote:
>
>Emile, essentially, the situation is that I'm trying to create an API
>for consumption scripting. As it stands now, in initial development
>they can pass callback function. The idea was to enable them to pass
>variables and have the handling function determine the type and just
>drop the value into it instead of calling function with the value as
>an argument. The problem with that approach is determining exactly
>which variable was passed. My idea was to use this to capture the name
>and then modify the globals for the executing frame so that the passed
>variable represents the new value.
You're making some rather dangerous and unwarranted assumptions here.
Consider your original code:
def MyFunc ( varPassed ):
print varPassed;
MyFunc(nwVar)
What's going to happen if I do this:
MyFunc( nwVar+1 )
MyFunc( 27 )
MyFunc( "abcde" )
If the thing passed in is a list or an object, you can modify the object in
place without trickery. You can check that with the "type" operator:
if type(varPassed) == list:
pass
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list