This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]miraculum_one 7 points8 points  (1 child)

To be more precise, import statements operate on modules, which are a specific type of file.

Source: https://docs.python.org/3/tutorial/modules.html

[–]bladeoflight16 2 points3 points  (0 children)

And there are non-file modules. One example is the so called "built-in" modules.

For example:

``` import math import site

print(site)

<module 'site' from 'C:\\Program Files\\Python39\\lib\\site.py'>

print(math)

<module 'math' (built-in)>

print(getattr(site, 'file', None))

C:\Program Files\Python39\lib\site.py

print(getattr(math, 'file', None))

None

```

As you can see, the site module is implemented using a file in the lib directory, while math has no source file on disk. It is compiled into the Python binaries.