版本记账是在导入之前还是之后?

2024-10-05 13:14:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望在我提交给Mercurial的一些python脚本中使用版本记账。你知道吗

我打算按照https://www.python.org/dev/peps/pep-0008/#version-bookkeeping中的说明操作,但我不确定

before any other code, separated by a blank line above and below.

指进口前。是吗?我这么问是因为有些进口商品似乎必须放在最开始的时候,例如:

from __future__ import print_function, division, absolute_import, unicode_literals

Tags: httpsorgdevimport版本脚本versionwww
1条回答
网友
1楼 · 发布于 2024-10-05 13:14:01

These lines should be included after the module's docstring, before any other code, separated by a blank line above and below.

import语句是代码。您可以将它们放在try/except语句中以捕获ImportError,不太常见的情况下,它们可以在函数和类语句中使用。所以这在模块docstring之后,在导入之前。你知道吗

I am asking because some imports seem to have to be placed at the very beginning[...]

__future__语句不仅仅是普通代码。编译器(与解释器相反)和have to come before you start assigning variables or importing other modules可以理解它们:

A future statement must appear near the top of the module. The only lines that can appear before a future statement are:

  • the module docstring (if any),
  • comments,
  • blank lines, and
  • other future statements.

因此,如果您的版本控制crud是一个注释,您可以将它放在将来的语句之前。但如果它是一个真正的变量,它就必须去追求。你知道吗

相关问题 更多 >

    热门问题