Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 modifying variables in local or global space
#1
you can't modify variables in local space using they dictionary you get from locals() or the reference you can track down from inspect.currentframe(). is there any way to do this, at all? can globals be safely modified since all the documents that touch on this topic seem to focus only on locals?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#2
(Aug-14-2019, 03:55 AM)Skaperen Wrote: you can't modify variables in local space using they dictionary you get from locals()

but.... I can

>>> l=locals()
>>> l["foo"] = "bar"
>>> print(locals())
{'__spec__': None, '__builtins__': <module 'builtins' (built-in)>, '__name__': '__main__', '__loader__': <class '_frozen_importlib.BuiltinImporter'>, 'foo': 'bar', '__package__': None, '__doc__': None, 'l': {...}}
Quote
#3
by "can't" i meant that you are not supposed to according to Python documentation. it is CPython specific according to one source. another source said it is something about how compiled code accesses the namespace at runtime. yes, if you try, it looks like it works. it works most of the time. it sometimes fails.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  problem using exec to save local variables dkarl 0 98 Dec-01-2019, 08:52 AM
Last Post: dkarl
  Global Variables - Some Points Needing Clarification. adt 4 186 Nov-30-2019, 01:23 PM
Last Post: adt
  visibility/space of variables. Pls help. gtlhbkkj 1 87 Oct-12-2019, 05:51 PM
Last Post: buran
  Global variable does not seem to be global. Columbo 6 403 Jul-15-2019, 11:00 PM
Last Post: Columbo
  Global variables not changing ThemePark 3 423 Mar-02-2019, 11:24 AM
Last Post: Larz60+
  help with threading module and passing global variables ricardons 1 802 Feb-21-2019, 12:48 PM
Last Post: stullis
  Use of global variables from several modules. Jstechg 3 493 Jan-03-2019, 03:39 AM
Last Post: scidam
  Resetting Global Variables? WuchaDoin 11 1,194 Sep-28-2018, 08:41 PM
Last Post: WuchaDoin
  Trouble with global variables maymac789 1 585 Mar-29-2018, 03:15 AM
Last Post: Mekire
  Is This Code Ok? How Can I Avoid Using Global Variables? digitalmatic7 9 1,554 Feb-15-2018, 09:32 AM
Last Post: DeaD_EyE

Forum Jump:


Users browsing this thread: 1 Guest(s)