txt interpretation module
When creating a new package, there will be an init new file
pip installs the library file When the import import is invalid,
there are three types of modules:
standard library, third-party, custom module How to call
import: 1 Execute the corresponding file 2 Import the variable name
import cal
from cal import cal
from day import cal# don't know cal but know day, the best way
print(cal.add(3,5))
Function function module cal.py
#This module only puts functions as function modules def add(x,y): return x+y def sub(x,y): return x-y
Execute function module bin.py
# import cal will execute all functions once, # # print(cal.add(3,5)) calls the function in the cal module by clicking # print(cal.sub(3,5)) # #You can run to get the result , but there are red # import cal, time can import multiple commas # from cal import add # from cal import sub # from cal import *# This writing is not recommended # print(add(3,5)) # print(sub (3,5)) # import sys # print(sys.path) # from day import cal# I don't know cal but know day, successful # print(cal.add(3,5)) # print(cal.sub( 3,5)) from day import main main.run()
main module main.py
#Main file from day import main #To execute main, you must first import from day import cal def run(): print (cal.add(3,7 )) print (cal.sub(3,7))