Friday, April 5, 2019

python - Can I import my own custom modules without using os.chdir()?

I've been following the guide here for creating and importing your own custom modules, but I seem to be missing something.


So far, i have done:



  1. I have the directory C:\Users\Me\OneDrive\CustomModules\MathFunctions.

  2. Added C:\Users\Me\OneDrive\CustomModules to my system environment PATH.

  3. Under MathFunctions, I have 2 files: __init__.py and Functions.py.


After starting Python, simply typing


from MathFunctions import Functions  # Doesn't work

as the guide shows doesn't work.


However, if I use the os.chdir() first, it works:


import os                                       # Works
os.chdir('C:/Users/Me/OneDrive/CustomModules')
from MathFunctions import Functions

Is there some way to avoid using os.chdir()? Or is that a necessary step every time?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...