Where exactly are modules being stored in order for us to “import” them? Because this is a generic question, I won’t post a link to a specific exercise.
There’s a search path, python will look through it until it finds that module, or not.
Some modules may also be built into python (so it wouldn’t be anywhere in your filesystem)
>>> import sys >>> sys.path ['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/nate/.local/lib/python3.6/site-packages', '/usr/lib/python3.6/site-packages']
The empty string is the current directory, some modules that ship with python are in a zip file apparently, some are installed by my operating system, no clue what lib-dynload is, some are packages in my home directory
So based on the path, it comes from the user library. I’m assuming this means that when a Python compiler were downloaded it would download certain modules with it?
So the file marked “Nate” was downloaded into a file on your home page or desktop? That one seems interesting, because its a different file path.
nate is my username, /home/nate is my home directory, tbh I’m not sure there’s a “desktop”, maybe there is
While all languages are both compiled and interpreted, python is generally thought of as interpreted - it doesn’t compile to machine code and the compilation step is barely worth mentioning
But yes, python (and most languages really) ships with a standard library which is in the form of a bunch of modules
Okay, so if I were to download a Python interpreter so I could code on my computer, would it bring all the modules with it and store it in user libraries?
No such thing as all, but those which are part of the language, yes
… I could do this:
# aoeu.py x = 5
from aoeu import x print(x) # 5
…that wouldn’t be included with python
I see, module just refers to a generic function, but some are stored in libraries and come with Python.
They’re not functions, you can’t call them
When you create a file and put python code in it, that is a module
But you could create them in other ways too, you could write code that creates a module. Some may be part of the interpreter itself. Some might be written in C
Okay, one last question. How does the datetime work if its pulling out of libraries from when I downloaded Python? Does it access the date and time information my computer has or does it access some atomic clock on some server somewhere?
I don’t dare say exactly what it’s defined as, but it boils down to what your operating system says the time is
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.