Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create a function that will create a global (and assign it a value) with a name that contains the name of the argument given to it?
    primarykey
    data
    text
    <p>I'm using Python and am trying to create a function that will look at the name of the object that is given as an argument and (among other things) create some globals that contain this name, for example:</p> <pre><code>object1=someclass(args,kwds) #the object is an instance of a class that is given a certain name (e.g.object1) def somefunc(some_argument): global tau_some_argument global ron_some_argument #e.t.c. for other variables (I also would like to assign some variables etc) tau_some_argument=some_value1 ron_some_argument=some_value2 print ron_some_argument print tau_some_argument </code></pre> <p>now what I want to happen if I call this function is as follows: when I call</p> <pre><code> somefunc(object1) </code></pre> <p>I would like it to create some globals named tau_object1, ron_object1 and assign them values (the print statements are irrelevant), similarly if i called</p> <pre><code>somefunc(object2) </code></pre> <p>where object2 is another instance of a class I would like it to create globals: tau_object2, ron_object2, at the moment the function simply creates globals named tau_some_argument (as is obvious from the code).</p> <p>Now I read somewhere that the names of python objects are immutable, unless they are a class or function so I don't know how to do this, from reading I get the feeling that I may need to use meta-classes but this feels like it's an overly complicated way of doing something that should be relatively easy.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload