I'm trying to learn python and I'm having trouble importing a module. I have a .pyc file that I'm trying to import into idle shell called dfa.pyc
I have the file in a folder called xyz. I navigate to this folder using:
os.chdir('/Users/xxx/Desktop/xyz')
So now, if I try to run the command:
from dfa import *
i get the error:
ImportError: No module named dfa
If i run the command:
os.path.isfile('dfa.pyc')
it returns true.
Can someone explain how i can get the dfa.pyc file imported?
Thanks
The Import-Module cmdlet adds one or more modules to the current session. Starting in PowerShell 3.0, installed modules are automatically imported to the session when you use any commands or providers in the module. However, you can still use the Import-Module command to import a module.
I don't think python modules are loaded I based on what you do with chdir. Modules are loaded from the folder you started the python shell and folders in PYTHONPATH.
If you want dynamically load modules maybe you can check imp.loadmodule (sample in the bottom of the page).
you can add to the PYTHONPATH in code by doing
sys.path.append('<newpath'>)
from dfa import *
I don't believe changing your current directory has any impact on the import process and even if it did, I'm not sure that's how you would want to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With