简体   繁体   中英

Defining external path variable for python package on installation

If I have a Python package, foo , and I want a path variable that is user-defined during package installation ( foo.ext_path = '/Home/User_name/Data_files/foo_data' or something), what is the best/recommended/most pythonic manner to accomplish this? I do not want to include the data within the python package; this is something that is both necessary to run foo, and necessary for the user to provide.

Required configuration usually falls into the category of things belonging in an external configuration file.

The package can define a configuration file path, in posix this is usually something under /etc , and ask that the user populate it with appropriate entries for their configuration.

Best practice is for the package to create an example configuration file for example /etc/my_package/my_package.example or similar, to show all available configuration entries and example values.

Python has built in support for configuration files via ConfigParser though YAML based config files are usually easier to use and frequently more common.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM