I am kind of baffled by this code in the `__init__.py` file in my Python project. How does this work internally?

So, I have the following Python code residing in the __init__.py file of my Python project which I autogenerated using PyScaffold.

from pkg_resources import get_distribution, DistributionNotFound

try:
    # Change here if project is renamed and does not equal the package name     dist_name = 'mlfq-sim'
    __version__ = get_distribution(dist_name).version
except DistributionNotFound:  # pragma: no cover     # Can't unit test this for now since I do not know how to temporarily     # remove a distribution during runtime. Help. Also, is this even     # worth it?     __version__ = 'unknown'

Enter fullscreen mode Exit fullscreen mode

I get that it gets the version of my project. But how does it do it? Is there a benefit in using it compared to the one below?

__version__ = 'some version'

Enter fullscreen mode Exit fullscreen mode

原文链接:I am kind of baffled by this code in the `__init__.py` file in my Python project. How does this work internally?

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容