This may be a broader question and more related to understanding the nature of Python and probably good programming practice in general.
I have a file called util.py. Over the past few months, he has been collecting many small functions that are useful in performing various machine learning tasks.
My thinking is this: I would like to continue adding important functions to this script when I go. Thus, I want to use import util.pyoften, now and in the future, in many unrelated projects.
But Python seems to feel that I only need to have access to the code in this file if it lives in my current state, even if the functions in this file are useful for scripts in different directories. I feel some reason for what works, which I do not fully understand; it seems to me that I will often be forced to make unnecessary copies.
If I have to create a new copy util.pyevery time I work from a new directory, in another project, it will not be long until I have many different versions / iterations of this file scattered throughout my hard drive in different states. I do not want such a degree of modularity in my programming - for the sake of simplicity, repeatability and clarity, I want only one file to be in one place accessible to many projects.
Question in a nutshell: What is the argument for Python that seems to frown when importing from different directories?
source
share