https://packaging.python.org/tutorials/packaging-projects/
創建PyPi賬號
創建自己的模塊
創建項目dict2obj,代碼結構入圖所示。
1、dict2obj、license、readme、setup爲原始文件(必要)
2、build、dict2object.egg-info、dist 爲執行python setup.py sdist bdist_wheel
生成的最終文件(生成所得)
3、demo1爲測試文件(測試)
上傳至PyPi
安裝twine
python -m pip install --user --upgrade twine
生成文件
python setup.py sdist bdist_wheel
上傳文件
python -m twine upload dist/*
注意
setup.py很重要
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
VERSION = '1.0.0'
tests_require = []
install_requires = []
setup(name='dict2object',
url='https://github.com/',
author="Emory Yan",
author_email='[email protected]',
keywords='python dict2obj dict obj',
description='Automatically register models in the admin interface in a smart way.',
license='MIT',
classifiers=[
'Operating System :: OS Independent',
'Topic :: Software Development',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: PyPy'
],
version=VERSION,
install_requires=install_requires,
tests_require=tests_require,
test_suite='',
extras_require={},
entry_points={'nose.plugins': []},
packages=find_packages(),
)
安裝使用
pip install dict2object
import dict2obj
dd = {'name': 'xxx', 'sex': '男'}
print(dict2obj.dict_to_object(dd).name)
print(dict2obj.dict_to_object(dd).sex)
>> xxx
>> 男