While the Python3 import statement is the pythonic way to do so. I will introduce a PHP inspired way with a function named include that has assisted me along the journey of programming.
python3_source_code_textfile = '/path/filesystem/source1.py'
with open(python3_source_code_textfile) as f: exec(f.read(), globals())
What this does it will import everything within the file, variables, functions, methods, classes, etc.
Happy Coding as always!
A word on agentic text generation. As quick producing as source code from LLM can be. I’d say, you perhaps don’t gain the problem solving skills as developing a solution from an idea. Though, checking how the LLM would do it, then improving upon it, may be an option. Great for experts to increase their productivity, not so much on the bottom rung, but code assistance of LLM are just that, a balancing act of having the LLM produce what is asked, and programming to get a task done with those of long ago software development methodology techniques and SDLC (Software Development Life Cycle) of waterfall, iterative, etc. that aren’t fussed about anymore, eroded from agile, scrum, and now vibe.
I’ll just place this comment here.
The goal is always to write high quality, maintainable (human readable) code. I’m not in the camp that says code is a liability, simply because millions of lines of code is time constraint detriment (to read and understand the code of massive code repositories for expert level know-how). However, the less code that is high quality, easily human readable and maintainable, the better, that accomplishes the project from the idea to implementation.
Law of Human Readability of Source Code
So if a million lines of code can be refactored great, if a few thousands lines can be refactored, that’s ok. A few hundred lines of code and the tradeoff is perhaps not suffice of the expert programming effort in select situations (unless an incredible operating system kernel, or you like tidy neat source code, is being created to say, run the AI on a Star Ship Discovery, etc.), you get the idea. To Refactor or Not to Refactor, that is the question.