For a Python module, what are the standard global variables to declare?
In reading other Python modules, I've seen that many people often include __version__
and __author__
global variables in their source files (its even mentioned in PEP3001). I'd like to document my code with a reasonable set of these variables. What is a list of global variables that might be commonly included?
There isn't a specific standard for those global variables - as noted in the PEP you linked, they were attempts to achieve a standard but haven't become universally accepted in any singular form.
The real standard is the PyPI metadata, which is specified in the setup.py
file for your module, using distutils
(or a compatible interface). Here's the example from the packaging tutorial:
from distutils.core import setup
setup(
name='TowelStuff',
version='0.1.0',
author='J. Random Hacker',
author_email='jrh@example.com',
packages=['towelstuff', 'towelstuff.test'],
scripts=['bin/stowe-towels.py','bin/wash-towels.py'],
url='http://pypi.python.org/pypi/TowelStuff/',
license='LICENSE.txt',
description='Useful towel-related stuff.',
long_description=open('README.txt').read(),
install_requires=[
"Django >= 1.1.1",
"caldav == 0.1.4",
],
)
http://guide.python-distribute.org/creation.html
Use distutils
(or the superset setuptools
) instead to provide metadata about your project.
Especially when using setuptools
, that metadata is then discoverable and reusable through the pkg_resources
module.
There is no standard for global variables such as __version__
, not even for the Python stdlib, which is why the effort to provide this metadata in the stdlib for Python 3 has not amounted to anything.
I can recommend the Python Packaging User Guide as a primer on how to package your project properly.
链接地址: http://www.djcxy.com/p/11772.html上一篇: 如何让☆在中心旋转?