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
- Create a dir with modulename
- Must have a init.py file
-
Can set ALL = [‘filename’, ‘filename2’],
this will support import * - 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
-
blogger_postdir.py:
import bloggerAUTH as AUTH
-
init.py:
from .bloggerAUTH import *
-
bloggerAUTH.py:
from .myBlogIDNumber import BLOG_ID
-
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 ```