Python Forum
How to avoid exec(), globals(), locals(), eval()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to avoid exec(), globals(), locals(), eval()
#7
@bowlofred
ok my mistake to not being precise enough; the current post is in the continuity of this one (I thought it was a better idea to open a new one to speak about the use of exec(), locals(), globals() and eval()).
(print is just a way highlight my need)

Currently:
  • I'm dealing with a lot of data that are recorded in a first time in dictionaries
  • the name of a dictionary depends on what I'm getting, so it's implicitly a variable
  • the number of dictionaries varies
  • the keys name is also a variable
  • values are (numpy) arrays (containing millions of rows and up to dozens of columns - in other word the size of the array can be huge)
  • in parallel to dictionnaries creation, a dictionnary names list is created and updated
  • because of all these variables, I'm using a mix of exec(), locals(), gobals(), eval() to dynamically work with names (for dictionaries, keys, and so on) and I know it's not a correct way to do under Python (for all reasons ever evocked)

In a first stage, and based on the list of dictionary names, I do not know how to pass to a function a variable number of dictionaries except using exec() and so on.

Hope it is clearer now
(one issue after another one Wink)
Reply


Messages In This Thread
RE: How to avoid exec(), globals(), locals(), eval() - by paul18fr - Apr-21-2021, 10:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  why globals() exits python when quit() is aliased as q abc12346 4 823 May-23-2023, 08:56 AM
Last Post: Gribouillis
  exec in a function paul18fr 6 3,642 Apr-19-2021, 11:10 AM
Last Post: paul18fr
  exec + subprocess = UnboundLocalError paul18fr 6 3,732 Feb-04-2021, 06:27 AM
Last Post: Gribouillis
  int, floats, eval menator01 2 2,547 Jun-26-2020, 09:03 PM
Last Post: menator01
  exec() in class, NameError niski1996 6 4,222 Apr-20-2020, 07:14 PM
Last Post: niski1996
  Is this use of exec pythonic? psolar 1 1,921 Feb-07-2020, 12:23 PM
Last Post: buran
  problem using exec to save local variables dkarl 0 1,865 Dec-01-2019, 08:52 AM
Last Post: dkarl
  common code, def a function vs exec() a string Skaperen 7 3,632 May-27-2019, 10:13 AM
Last Post: heiner55
  eval lambda function with restricted context Olivier 7 5,378 Mar-04-2019, 10:45 PM
Last Post: Olivier
  eval not working in code jamminjamie 0 2,282 Dec-27-2018, 05:24 PM
Last Post: jamminjamie

Forum Jump:

User Panel Messages

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