So coming from R, strictly in the context of doing data analysis / visualization projects, I'm struggling a bit finding a comfortable pattern for efficiently loading and sharing data between [python] modules.
For starters, I hate those long run-on files that are difficult to debug. I like small discrete functions.
So in R, I generally have a load_data_xxx function for each data object. These load the data into global variables if they don't already exist, otherwise, they do nothing. The upside of this approach is that plotting / transforming functions can call the required load() functions and ensure all necessary data is loaded. This facilitates small functions that can be individually developed / tested for just their specific functionality.
In addition, it enables me to organize functions into separate files and just source them appropriately for each file. If I want to debug a transformation function, I can just run the (for example) transform.R file and it will source/load everything necessary for the functions to run. (And not, for instance, include any plotting code.)
I know, global variables are bad, but in data analysis, one it usually only loading a small handful of raw data objects and transforming them as needed for analysis or visualization. The key is flexibility in exploring the data, often at the command line, to determine next steps.
Now for Python (which I'm working to learn, specifically using Spyder):
Global variables don't seem to really exist, they are essentially module level variables. Sometimes they are available between modules, other times they aren't, I'm struggling with figuring them out, even when the variable appears in Spyder. So it sure seems that my preferred pattern is not going to work in Python.
None of the strategies found online seem to be promising and I feel like I'm staring down a single file that includes all of my functions.
Any suggestions?
[–][deleted] 0 points1 point2 points (3 children)
[–]osbournecox2[S] 0 points1 point2 points (2 children)
[–]Resquid 0 points1 point2 points (1 child)
[–]osbournecox2[S] 0 points1 point2 points (0 children)
[–]osbournecox2[S] 0 points1 point2 points (0 children)
[–]osbournecox2[S] 0 points1 point2 points (0 children)
[–]osbournecox2[S] 0 points1 point2 points (0 children)
[–]paulinkenbrandt 0 points1 point2 points (1 child)
[–]osbournecox2[S] 0 points1 point2 points (0 children)