Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
import vs inserting code
#6
(Jun-21-2024, 05:47 AM)rodiongork Wrote: what is your goal, if it may be asked?

the goal is to have that insert effect, such as doing stuff with the local namespace in ways where doing a common thing is the way, such as having the logic in multiple places that all still need to access the same local namespace. i just got done writing 6 different command scripts that each needed a lot of the same code. it would have been very awkward, at best. for the common code to be there just once and the difference code to be refactored to choose what to do based on which command i being run (yes, i have written command code that varies what it does based on the named it was run as, in Bash, C, and Python).

a function certainly should not access caller local namespace. but, in some cases, you need to work with local namespace in some common way in many places. it looks bad to have duplicate code; people end up looking to see how those chunks of code might be different. how can Python let you have just one copy of code, so that it is can be used in many places and is clear to be the same thing without the limitations of a function call.

imagine a function that returns a dictionary of things that need to be changed. that's going to be some messy code to handle it. and that code could benefit from a means to insert it in each place the function that returns the dictionary is called.
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
import vs inserting code - by Skaperen - Jun-14-2024, 01:18 AM
RE: import vs inserting code - by rodiongork - Jun-19-2024, 07:55 PM
RE: import vs inserting code - by Gribouillis - Jun-19-2024, 09:42 PM
RE: import vs inserting code - by Skaperen - Jun-20-2024, 10:38 PM
RE: import vs inserting code - by rodiongork - Jun-21-2024, 05:47 AM
RE: import vs inserting code - by Skaperen - Jun-22-2024, 01:21 AM
RE: import vs inserting code - by Gribouillis - Jun-22-2024, 08:14 AM
RE: import vs inserting code - by Skaperen - Jun-23-2024, 01:54 AM
RE: import vs inserting code - by Gribouillis - Jun-23-2024, 06:52 AM
RE: import vs inserting code - by AdamHensley - Jun-23-2024, 12:02 PM
RE: import vs inserting code - by Skaperen - Jun-26-2024, 09:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  visual studio code python how to get source code of import module definitian umen 2 4,200 Jun-13-2020, 06:20 PM
Last Post: umen

Forum Jump:

User Panel Messages

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