Is it possible to include csv file as part of python package [duplicate]

与世无争的帅哥 提交于 2020-12-24 17:40:33

问题


Is it possible to include a csv file as part of python package?

I am creating a package and want some default config files which are imported at runtime.

I know I can store as a list or other structure in a .py file, but this will break the pattern I'm building against.


回答1:


This can be done in a two-step process, as detailed here.

You need one file in the root of your source, MANIFEST.in which reads:

include path/to/yourfile.csv

and you also need to add include_package_data=True, to the setup() function in setup.py. Tried and tested.




回答2:


I guess that you may use a specific module more than an "homemade version" to store configuration. In your case: The Python standard library includes the ConfigParser module, which handles ini-style configuration files for you.



来源:https://stackoverflow.com/questions/25531476/is-it-possible-to-include-csv-file-as-part-of-python-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!