getting name of passed reference

Dave Angel davea at ieee.org
Tue Dec 29 15:09:29 EST 2009



Joel Davis wrote:
> On Dec 29, 11:21 am, Emile van Sebille <em... at fenx.com> wrote:
>   
>> <snip>
>> In an extremely controlled situation you may avoid headaches when
>> deploying this kind of technique.  Regardless, we all want to make you
>> aware that this _will_ likely cause headaches, and, idle curiosity
>> aside, none of us can imagine the problem to which this is the
>> appropriate solution.
>>
>> It's fun to work out, but you're probably better served if you describe
>> the problem you're solving and consider the alternatives suggested.
>>
>> Dependence on introspection belongs in programming tools, not in
>> applications deployed across versions and platforms.
>>
>> Emile
>>     
>
> 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.
>
>   
I've never heard of "consumption scripting."  Can you describe it in 
simple terms?

I take it you're publishing a library of code that somebody can call to 
do things.  Can you characterize your users?  Are they programmers, are 
they Python programmers, are they scientists?

Presumably you're trying to define a language (not Python) that these 
users can program in, where you want to achieve call by reference.  I'm 
sure you have some good reason for that, but could we hear it?

When you need to do something like this for programmers, the approach 
might be for them to pass a collection object, and an identifier to 
specify what part of the collection for you to modify.  If the 
collection object is their module, then the identifier could be just the 
name of the identifier they want you to modify.  In this case, the code 
could be robust and readable.

Even better would be for them to pass you an object, and you can call 
methods on that object to modify it in place.  Just provide them a class 
to create such an instance, and they can have as many of them as they like.

DaveA




More information about the Python-list mailing list