python - 如何将多个函数打包到一个python包并上传到PyPI
问题描述
我创建了一个 python 包,theanwer
. 这是PyPI和GitHub 上的内容。它只有一个功能,theanswer()
. 安装后:
import theanswer
theanswer.theanswer()
按预期返回42
。
目录结构为:
theanwer/
theanswer/
__init__.py
setup.py
__init__.py
包含:
def theanswer():
return 42
if __name__ == "__main__":
theanswer()
setup.py
包含:
setup(name='theanswer',
version='0.1',
description='answer to the ultimate question',
url='https://github.com/zabop/PyPIattempt',
author='Pal Szabo',
author_email='szabopal96@gmail.com',
license='MIT',
packages=['theanswer'],
zip_safe=False)
现在,如果我想在答案包中包含此代码:
def returnthis(this)
return this
我想用它作为:
theanswer.returnthis(this)
归来this
。我怎样才能做到这一点?文件应该是setup.py
什么样子,我需要使用什么目录结构(才能将其上传到 PyPI)?
我对目录树的想法:
theanwer/
theanswer/
__init__.py # containing the function theanswer
returnthis/
__init__.py # containing the function returnthis
在setup.py
文件中,包应该是packages=['theanswer','returnthis']
.
这是一种方法吗?
解决方案
推荐阅读
- javascript - 如何防止下一行 \n 在电子邮件文本中被删除?
- android - SQLiteBlobTooBigException:行太大,无法放入 CursorWindow requiredPos=0,totalRows=1
- swift3 - 滑动手势快速分页 3
- reactjs - Redux-Form:如何在 Saga 中模拟 getFormValues 进行测试
- r - 来自非数值数据帧的平均值和 SD
- azure - 通过 ARM 模板部署时的 Azure 函数暂存槽交换错误
- google-bigquery - How to pass list of columns from one table to another table in bigquery
- java - 如何将 LinkedHashMap 转换为 Map
在 Java 中? - symfony - 动态延迟加载服务
- sql-server - SQL Server 在请求事务期间卡住了一张表