About python modules

Quick note. Read more at python doc: doc/tutorial/modules.html

A.
Outside module, just use
import sameDirfile
Then can use sameDirfile var

B. Module

  1. Create a dir with modulename
  2. Must have a init.py file
  3. Can set ALL = [‘filename’, ‘filename2’],
    this will support import *

  4. to load external var to init.py, use:

from .filenameSameDir import varname
Or all things
from .filenameSameDir import *

Example module:

./README.md  
./blogger_postdir.py  
./bloggerAUTH:  
    __init__.py  
    bloggerAUTH.py  
    myBlogIDNumber.py  
  
  1. blogger_postdir.py:
    import bloggerAUTH as AUTH

  2. init.py:
    from .bloggerAUTH import *

  3. bloggerAUTH.py:
    from .myBlogIDNumber import BLOG_ID

  4. myBlogIDNumber.py:
    BLOG_ID = 13345

Notes

So 0 loads 1
And 1 loads everything from 2
And again 2 loads a single var from 3

From 0, can access AUTH.BLOG_ID

Package and module is different

OK:
from time import sleep as tsleep

NOT OK:
import time.sleep as tsleep

ModuleNotFoundError: No module named ‘time.sleep’; ‘time’ is not a package ```