是否可以将csv文件作为python包的一部分包含在内 [英] Is it possible to include csv file as part of python package

查看:33
本文介绍了是否可以将csv文件作为python包的一部分包含在内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将csv文件作为python软件包的一部分包含在内?

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.

我知道我可以将列表或其他结构存储在.py文件中,但这会破坏我正在构建的模式.

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.

推荐答案

这可以通过两步过程完成,详细说明

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

您需要在源代码的根目录中找到一个文件,即 MANIFEST.in ,该文件的内容为:

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

include path/to/yourfile.csv

,还需要在 setup.py 中的 setup()函数中添加 include_package_data = True .经过尝试和测试.

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

这篇关于是否可以将csv文件作为python包的一部分包含在内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆