It was just the time to learn the logging module. The code is this:
Logging.basicconfig (filename= ' Test.log ', level=logging. DEBUG, format= '% (name) s% (asctime) s% (module) s-% (Lineno) d [% (levelname) s]:% (message) s ', datefmt= '%y-%m-%d%h:%m:%s ') logging.warning (' Test warning ') logging.info (' Test info ') logging.debug (' Test Debug ')
Above the Logging.basicconfig () to a bunch of parameters, and experiment, it seems necessary to use key parameters, not lazy. So curious to see the help
Import Logginghelp (logging.basicconfig) # below is the first 2 lines of help, followed by the Help on function basicconfig in module logging:basicconfig ( **kwargs) # It used to be a non-fixed parameter
Look, the whole is a non-fixed parameter, then only one of the honest one wrote. But when I think about it, the **kwargs will turn the key parameters into a dictionary, then the problem is:
Now that I'm going to become a dictionary, I'll just define a dictionary and pass in a dictionary.
Import logging# to define the parameters as a constant, put them in the configuration file or at the beginning of the file. In addition, format is too long to be written separately. Log_format = '% (asctime) s% (module) s-% (Lineno) d [% (levelname) s]:% (message) s ' Log_kwargs = {' filename ': ' Test.log ', ' Level ': Logging. DEBUG, ' format ': Log_format, ' datefmt ': '%y-%m-%d%h:%m:%s '}logging.basicconfig (**log_kwargs) # Word Logging.warning (' Test warning ') logging.info (' Test info ') logging.debug (' Test Debug ') can be passed into the dictionary as a parameter before the code is added.
Now that the dictionary can pass the argument, the array is the same.
def deal_list (*args): print (args) def deal_dic (**kwargs): Print (Kwargs) deal_list (*[1,2,3,4,5]) # *args is to turn parameters into tuples, so here Print out a tuple deal_dic (**{' a ': 1, ' B ': 2})
Python imports directly into the non-fixed parameters of a function with a dictionary array