How does Python import modules?


#1

If I tried to import a file on, say, a Raspberry Pi with no internet connection, would it import? I’m just wondering how exactly importing modules works.


#2

Any modules that are bundled with your installation of Python are available offline. On your device it may not be as large as a desktop version, but you should be able to find out what modules are shipped with the version for it.

https://www.raspberrypi.org/documentation/usage/python/

The above site has a forum which would be a good place to search for (or ask about) what modules are availabe out of the box.


#3

Thank you for your explanation, but if some modules are available offline, why do they have to be imported instead of being already loaded?


#4

To conserve memory. Modules are installed on the storage device inside a Python system folder and only loaded to memory when imported.


#5

That was what I assumed, I just wanted to make sure. Thank you.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.