Python Forum
exec() instead of functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
exec() instead of functions
#1
if i have some code that i want to collect all of its result values into an object and also run that code again in a different context and sane its different result values into another object, using a function for the code requires explicit context references, such as a dictionary style reference or a attribute style reference. i am looking at using exec() for this context switch. this way i don't need to have the code reference any context. the code assigns to simple variables in its single local and global context, and this gets returned by exec(). executed twice with separate contexts provided and returned looks like an easier way to go. coded variables can all be simple assignments. the big issue is where to put that source. a separate file would be easy to create. a big (triple quoted) string that has the source is another. but i am afraid that smart editors would treat that quoted code like any quoted text, making it hard to do it all in one file like that.
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
exec() instead of functions - by Skaperen - Aug-01-2020, 05:37 AM
RE: exec() instead of functions - by Gribouillis - Aug-01-2020, 09:54 AM
RE: exec() instead of functions - by Skaperen - Aug-02-2020, 10:37 PM
RE: exec() instead of functions - by Gribouillis - Aug-02-2020, 10:53 PM
RE: exec() instead of functions - by Skaperen - Aug-03-2020, 10:29 AM
RE: exec() instead of functions - by Gribouillis - Aug-03-2020, 11:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  documentation is wrong for exec() Skaperen 9 3,510 Jul-28-2019, 02:49 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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