& package logging module

logging module

a logging module for logging, recording general user in the software.

# Define end log output format 
# Note 1: The directory log file
BASE_PATH = . OS . Path dirname ( . OS . Path dirname ( __FILE__))
logfile_dir = . OS . Path the Join ( BASE_PATH, 'LOG_DIR')
# Print (logfile_dir) Note # 2: log file name logfile_name = 'USER.LOG' # log directory does not exist if you create a defined IF not os. path. isdir ( : logfile_dir) os. mkdir ( logfile_dir) full # log file path logfile_path = OS. path. the Join ( logfile_dir, The logfile_name)






   




Note # 3: log configure the dictionary # note. 4: DEF get_logger ( user_type): # 1. Load Configuration dictionaries log to the logging module . Logging . Config dictConfig ( LOGGING_DIC) # 2. retrieve log objects, Logger = the logging. the getLogger ( user_type) return Logger Logger = get_logger ( 'User') Logger. info ( 'message log')



           
           

           
           
           

     
     
       

When a test is performed to prevent the automatic import function module

# Func () # __name__ name belongs to a module namespace 
# When we execute this module will have a Print (__ name__)
# in the current file name is: __ when main__ be imported: the name of the module
# Note: Remember - "main + Enter key
IF __name__ == '__main__':   # here to test the function Print ( 'perform testing functions in the current module ...') FUNC () the else: Print ( 'current modules introduced ... ')


   

   

Theory package

What is the package? 
Comes in a __init__. Py folder, the package can also be imported
and may import all modules together under the package Why use packages? Package management module can help us, there is a __init__ in the package. Py, by its management module to help us how to use the package? import the package. module name from the package import module name from the package. module name import module name what happens when introduced into the package 1. When the package is introduced, will package the __init__. Py generates a name space 2 . then the __init__ performed. py, will the __init__. All py names are added to the name space 3. next will package under the names of all modules loaded into the __init__. namespace generated py 4. introduced pointing module namespace is actually __init__. namespace py generated













 

 

Guess you like

Origin www.cnblogs.com/cyfdtz/p/11892369.html