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()
#3
(Apr-20-2021, 04:12 PM)ndc85430 Wrote: You don't say why you want to do this in the first place.

I guess you're right; in the case I'm currently working on, I'm facing to different difficulties:
  • for a function (i.e. as argument), I need to provide a list of dictionnaries
  • Dictionnaries names have been previously (dynamically) reccorded in a list, and I cannot use explicit names and numbers accordingly (but use a variable instead)
  • in the main code, I'm using exec(s) to replace the name by its variable; if a want to rewrite it in a function, well "goto" item 1 Big Grin


(Apr-20-2021, 04:12 PM)ndc85430 Wrote: can't you just use a dictionary to map the names to the dictionaries?

Well it seems I do not know how to proceed

Thanks for your interest
Reply


Messages In This Thread
RE: How to avoid exec(), globals(), locals(), eval() - by paul18fr - Apr-20-2021, 04:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  why globals() exits python when quit() is aliased as q abc12346 4 833 May-23-2023, 08:56 AM
Last Post: Gribouillis
  exec in a function paul18fr 6 3,650 Apr-19-2021, 11:10 AM
Last Post: paul18fr
  exec + subprocess = UnboundLocalError paul18fr 6 3,739 Feb-04-2021, 06:27 AM
Last Post: Gribouillis
  int, floats, eval menator01 2 2,551 Jun-26-2020, 09:03 PM
Last Post: menator01
  exec() in class, NameError niski1996 6 4,226 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,873 Dec-01-2019, 08:52 AM
Last Post: dkarl
  common code, def a function vs exec() a string Skaperen 7 3,639 May-27-2019, 10:13 AM
Last Post: heiner55
  eval lambda function with restricted context Olivier 7 5,390 Mar-04-2019, 10:45 PM
Last Post: Olivier
  eval not working in code jamminjamie 0 2,285 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