How to configure the file path for python
This article introduces the knowledge of "how to configure the file path for python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Get the file name of the module where the called function is located, and then get its path.
2. Compared with the path where the configuration file is located, the absolute path of the configuration file is obtained based on the relative path of the configuration file of the module file path and the parent path.
Example
Co_filepath = sys._getframe () .f_code.co_filenamehead, tail = os.path.split (co_filepath) conf_filepath = os.path.join (head,'.. / conf/log.conf') conf_filepath = os.path.normpath (conf_filepath) logsignleton = LogSignleton (conf_filepath) logger = logsignleton.get_logger () "how to configure the file path to python" is here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!