Are versions kept before or after import?

I am hoping to use Version Bookkeeping in some of the python scripts I submit to Mercurial.

I intend to follow the instructions at https://www.python.org/dev/peps/pep-0008/#version-bookkeeping , but I'm not sure if

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

means before import. Does it have? I ask because some imports seem to be placed at the very beginning, for example:

from __future__ import print_function, division, absolute_import, unicode_literals

      

+3


source to share


1 answer


These lines must be included after the docstring of the module, before any other code, separated by blank lines at the top and bottom.

Operators

import

is the code. You can put them inside try

/ operators except

to catch ImportError

, and less commonly they can be used inside functions and class operators. So this happens after the docstring module and before import.

I ask because some imported goods seem to have to be placed at the very beginning [...]



Operators

__future__

are not (just) regular code. They are understood by the compiler (as opposed to the interpreter) and must appear before you start assigning variables or importing other modules :

The following statement should appear at the top of the module. The only lines that can appear before the future expression:

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

So, if your version control is a comment, you can put it ahead of future assertions. But if it's a real variable, it should go further.

0


source







All Articles