Real-time graphs

S

Steve Holden

Peter said:
Terry Reedy wrote:

Suppose I have a string and I'd like to create a variable with its name.
How can I do that?

globals['varname'] = 3

difficult or impossible for function locals


Not difficult - only ugly, slow, and dangerous:
Not only ugly, slow and dangerous but also not guarantees to work on any
specific implementation.

nobody-expects-the-spanish-inquisition-ly y'rs - steve
 
P

Peter Otten

Steve said:
[No] guarantees to work on any specific implementation.

What do you mean - the locals() analogue to

globals()[name] = value

or my exec workaround?

def somefunc():
value = as_you_like_it
exec "%s = value" % name

inquisitively, far from Spain
Peter
 
S

Steve Holden

Peter said:
Steve Holden wrote:

[No] guarantees to work on any specific implementation.


What do you mean - the locals() analogue to

globals()[name] = value

or my exec workaround?

def somefunc():
value = as_you_like_it
exec "%s = value" % name

inquisitively, far from Spain
Peter
The locals() analog.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top