When I write a program in Python, I put everything in a script. Sometimes I need to experiment with modules, classes and methods before using them in my program and use the interpreter for this. At some point, I need to test stuff in the context of my program so I need the classes, methods and variables from my program.
Example: I want to experiment with sending XHR requests but first I need to do things my program do (instantiate classes, set some attributes, craft the url, parse the page,...). My workflow so far:
- Sometimes I just Copy/Paste the relevant parts from the script to the program which is tedious
If I use my script as a module, I can do:
import myprogram a = myprogram.test() ...
I heard about exec() which is very tedious to use (the whole command). When I used Matlab long time ago, I could simply execute a script in the interpretor then I would tinker with variables until I had the result I wanted.
How do you source a whole script in the interpreter?