我是靠谱客的博主 单身大侠,最近开发中收集的这篇文章主要介绍python可嵌入和可执行版本,将版本嵌入python包的标准方法?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Is there a standard way to associate version string with a python package in such way that I could do the following?

import foo

print foo.version

I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in setup.py already. Alternative solution that I found was to have import __version__ in my foo/__init__.py and then have __version__.py generated by setup.py.

解决方案

Not directly an answer to your question, but you should consider naming it __version__, not version.

This is almost a quasi-standard. Many modules in the standard library use __version__, and this is also used in lots of 3rd-party modules, so it's the quasi-standard.

Usually, __version__ is a string, but sometimes it's also a float or tuple.

Edit: as mentioned by S.Lott (Thank you!), PEP 8 says it explicitly:

Module Level Dunder Names

Module level "dunders" (i.e. names with two leading and two trailing

underscores) such as __all__, __author__, __version__, etc.

should be placed after the module docstring but before any import

statements except from __future__ imports.

You should also make sure that the version number conforms to the format described in PEP 440 (PEP 386 a previous version of this standard).

最后

以上就是单身大侠为你收集整理的python可嵌入和可执行版本,将版本嵌入python包的标准方法?的全部内容,希望文章能够帮你解决python可嵌入和可执行版本,将版本嵌入python包的标准方法?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部