I had developed 2 python (3.x) scripts. They each followed some basic flow in the body by calling these methods
- process_params()
- run(params)
I now have a use case where it is useful for my first python script to call a specific function in my second python script.
So, to prevent name conflicts of process_params()
and run(params)
, I did the following:
- Put both files in the same directory.
- In my first python script, I have essentially following:
sys.path.append(".")
from script2 import needed_function
To my horror and surprise, when I called "script1", it is invoking script2's process_params()
even though I didn't import it!!!
I then attempted to create a small-simple test case to demonstrate this unexpected behavior. However, I failed; the test case return what I expected by using the local process_params()
!
That means that there is something really odd (something that I messed up) in my actual code where script1 will call script2's process_params()
instead of its own local instance when I had only import a single and different method from script2. Since the problem is probably "unique" to how my actual scripts' code is; but the scripts are long and it has confidential information as well that I cannot post them here. Are there suggestions or theories that anyone can suggest on how I approach this problem?