David Beazley (PyCon2015) | Index


Part I : Basic Knowledge


Part II : Packages


Part III : __main__


Part IV : sys.path


Part V : Namespace Packages


Part VI : The Module

NOTE: A module is somenthing you can create on the fly:

import types
mod = types.ModuleType('spam')
print(mod)
# >> <module 'spam'>
print(mod.__dict__)
# >> {'__name__': 'spam', '__spec__': None, '__doc__': None,  '__package__': None, '__loader__': None}


Part VII : The Module Reloaded


Part VIII : Import Hooks

NOTE: You can “populate” a module you created with another module

import types, socket
mod = types.ModuleType('my_socket')
print(mod.__dict__)
# >> {'__name__': 'my_socket', '__doc__': None,  '__package__': None, '__spec__': None, '__loader__': None}
print(socket.loader)
# >> <_forzen_importlib.SourceFileLoader ...>
socket.loader.exec_module(mod)
print(mod.__dict__)
# now the mod.__dict__ is almost identical to the socket.__dict__ except for value in the '__name__'


Part IX : Path Hooks


Part X : Final Comments


Online Resources:

THE BEST video on the topic i could find: Youtube by ‘Sreekanth’