When present, what is the order that these elements should be declared in a Python module?
#!/usr/bin/env python)# coding: utf-8)from __future__ import unicode_literals, ...)If declared last, will the docstring work in a call help(module)?
Hash bang. The kernel literally looks at the first two bytes of the file to see if they are equal to #!, so it won't work otherwise.
Encoding. According to the Python Language Reference it must be "on the first or second line".
Docstring. According to PEP 257, a docstring is "a string literal that occurs as the first statement in a module, function, class, or method definition", so it cannot go after any import statements. You can see for yourself that help(module) no longer reports your docstring if you put it in a different place.
Future imports, because they cannot go before any of the above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With