Python Forum
namespaces in comprehension in exec()
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
namespaces in comprehension in exec()
#3
(Mar-27-2017, 08:40 AM)zivoni Wrote: why you need to pass locals anyway?

i am making "python format" config files.  that means lots of simple coding will be used that just does put things in the local namespace.

account = "080643210675"
vin = "1HGBH41JXMN109186"
phone = "+18009004321"
it doesn't have to be locals.  it just has to be somewhere.  if nothing else is added to to the space then there is the option to extract "misspelled" config options.  but the global space gets stuff added so it is to be avoid if that option is to be used.  my pyconf() function was intended to return a dictionary of what the config file set.  so, the issue of how comprehensions are used is going to be used will be the same in a python format config file as in regular code.  no big deal.  however people deal with it in regular code, just do the same in a python format config file.  use of comprehensions in config files is expected to be much less frequent in config files than in regular code.  and they are rare in regular code.  it was just a happen chance that i used one.  i did not know of the namespace isolation thing.  now i do.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
namespaces in comprehension in exec() - by Skaperen - Mar-27-2017, 07:08 AM
RE: namespaces in comprehension in exec() - by Skaperen - Mar-27-2017, 10:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Still not completely clear about namespaces... bytecrunch 3 2,010 Oct-07-2022, 05:44 PM
Last Post: bytecrunch
  How to avoid exec(), globals(), locals(), eval() paul18fr 10 5,190 Apr-21-2021, 05:53 PM
Last Post: snippsat
  exec in a function paul18fr 6 3,473 Apr-19-2021, 11:10 AM
Last Post: paul18fr
  exec + subprocess = UnboundLocalError paul18fr 6 3,591 Feb-04-2021, 06:27 AM
Last Post: Gribouillis
  Modules and namespaces (again?) ptrivino 1 1,886 Oct-24-2020, 10:37 PM
Last Post: Larz60+
  exec() in class, NameError niski1996 6 4,077 Apr-20-2020, 07:14 PM
Last Post: niski1996
  Is this use of exec pythonic? psolar 1 1,874 Feb-07-2020, 12:23 PM
Last Post: buran
  problem using exec to save local variables dkarl 0 1,830 Dec-01-2019, 08:52 AM
Last Post: dkarl
  common code, def a function vs exec() a string Skaperen 7 3,466 May-27-2019, 10:13 AM
Last Post: heiner55
  Parse XML with Namespaces dwill 7 20,628 Apr-12-2018, 09:22 PM
Last Post: dwill

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020