在Python包装sampleproject中,该模块有一个很长的描述,在client = Client(keys['apiKey'], keys['apiSecret'])
accounts = client.get_accounts()
for account in accounts.data:
txns = client.get_transactions(account.id, limit=25)
while True:
for tx in txns.data:
print(tx.id)
if txns.pagination.next_uri != None:
starting_after_guid = re.search('starting_after=(.*)', str(txns.pagination.next_uri), re.I).group(1)
txns = client.get_transactions(account.id, limit=25, starting_after=starting_after_guid)
else:
break
中使用:
setup.py
在使用# Get the long description from the README file
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
...
setup(
...
# This is an optional longer description of your project that represents
# the body of text which users will see when they visit PyPI.
#
# Often, this is the same as your README, so you can just read it in from
# that file directly (as we have already done above)
#
# This field corresponds to the "Description" metadata field:
# https://packaging.python.org/specifications/core-metadata/#description-optional
long_description=long_description, # Optional
安装模块后,用户如何以不同的格式访问此descprtion?
答案 0 :(得分:1)
import email
from pkg_resources import get_distribution
pkgInfo = get_distribution(package_name).get_metadata('PKG-INFO')
print(email.message_from_string(pkgInfo)['Description'])
package_name
必须是您的分发名称。 pkgInfo
是一个包含软件包所有元数据的字符串,因此我使用email
对其进行解析并返回Description
作为标头。一个小肮脏的把戏。