Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Carl Meyer Newsgroups: comp.lang.python Subject: Re: does the order in which the modules are placed in a file matters ? Date: Wed, 16 Dec 2015 09:19:18 -0700 Lines: 85 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="s84aUhKVeNw0gJU8e0EXo1qaHJSDc1hko" X-Trace: news.uni-berlin.de 1nw+SlmqfpNrvRZgb7cudwra/JbzVfyHPpjfvZedbZqg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; '"""': 0.05; 'sys': 0.05; '__name__': 0.07; 'lines.': 0.07; 'main()': 0.07; 'subject:file': 0.07; 'imports': 0.09; 'subject:modules': 0.09; 'subject:which': 0.09; 'python': 0.10; '2.7': 0.13; 'def': 0.13; "'__main__':": 0.16; 'constitutes': 0.16; 'filename:fname piece:signature': 0.16; 'from:addr:carl': 0.16; 'grouped': 0.16; 'guessing': 0.16; 'intervening': 0.16; 'main():': 0.16; 'pep8': 0.16; 'received:173.255': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:matters': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; 'later': 0.16; 'project,': 0.18; 'library': 0.20; 'enforce': 0.22; 'latter': 0.22; 'am,': 0.23; 'defined': 0.23; 'third-party': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'example': 0.26; 'linux': 0.26; 'logging': 0.27; 'order.': 0.27; 'question': 0.27; 'module.': 0.27; 'tend': 0.27; 'probably': 0.31; 'certain': 0.31; '[1]': 0.32; 'run': 0.33; 'url:python': 0.33; 'usually': 0.33; 'though.': 0.33; 'running': 0.34; 'something': 0.35; 'sometimes': 0.35; 'url:org': 0.36; 'modules': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'care': 0.60; 'your': 0.60; 'details': 0.62; 'charset:windows-1252': 0.62; 'matter': 0.63; 'within': 0.64; 'bothered': 0.66; 'opinions': 0.71; 'groups.': 0.72; 'unusual': 0.72; 'sounds': 0.76; '.etc': 0.84 X-Enigmail-Draft-Status: N1110 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: X-Spam-Status: No (score -1.0): ALL_TRUSTED=-1, URIBL_BLOCKED=0.001 X-Spam-Bar: - X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100523 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --s84aUhKVeNw0gJU8e0EXo1qaHJSDc1hko Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hi Ganesh, On 12/16/2015 09:09 AM, Ganesh Pal wrote: > Iam on python 2.7 and linux .I need to know if we need to place the > modules in a particular or it doesn't matter at all >=20 > order while writing the program As you've probably already noticed, it usually doesn't matter to Python (though it can become relevant in certain unusual circular-import cases). Most people will have some opinion about what constitutes good style, though. Opinions tend to look something like these (though details will vary): 1. All imports at the top of the module. 2. Standard library imports, then third-party imports, then local imports= =2E 3. Sometimes the above types of imports are grouped with intervening blank lines. 4. Sometimes imports are alphabetized within those groups. > For Example >=20 > import os > import shlex > import subprocess > import time > import sys > import logging > import plaftform.cluster > from util import run >=20 >=20 > def main(): > """ ---MAIN--- """ >=20 > if __name__ =3D=3D '__main__': > main() >=20 > In the above example : >=20 > 1. Iam guessing may be the python modules like os , shlex etc come > first and later the user defined modules like import > plaftform.cluster .etc come latter >=20 > Sorry if my question sounds dump , I was running pep8 and don't see > its bothered much about it AFAIK the pep8 module doesn't care about import order. If you'd like to enforce an import order in your project, you can look at isort. [1] Carl [1] https://pypi.python.org/pypi/isort --s84aUhKVeNw0gJU8e0EXo1qaHJSDc1hko Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBCAAGBQJWcY8GAAoJEC0ft5FqUuEhOYsP/3JmEXq/Y0bFKGjlQoPsCwiQ EBq2gAmFSHYgWbP/j2MChQ3iEdNtaNoTupIRAtkblf6ZSaQ0dSzABy7e57Gaj8fw fM6H20g/tYLqr2Wu8Icbc8mkRtiR6XSCIyoKyMUCEq9uMSakdBZDsPcYvUJyVr0H o0GsydfuE7ghvRzBTXq+hYm5BJ/tbfvBRvRpstSXLwUU3WfsTBM9rap8Vhy5cX3R /N1x9r22TqcWmPs91ctuDvXMzlyzIa5+g3pPKHL1jMTIxWkHieAKzpEZ1wOU267K QeMSUK3O0t0RiMYMXAhRofTzAXZ4vGBvlveDhXDJSrCsgBFNCZpmp9U+Wx3lOpLR j1HIjgPIaxI9OPZYTfYOdXqh+u5phwvLVU1V6sL6CF2XdEpdaKZnXBGGhal8C7p6 bQkx+Efw+zTgQzNBzM+EFIsH7uZyWN0oVJ2Gbu39zU+2dxcjeEuUSA6rIG4ncYl3 fzXr/utJFK8U/wRCcXMMl8iiHwdA0n+hqs8X07sruk/2v5xKaBZ/OGUUUcpK2GS5 P2m6jUBoZooTeKH/4PlhF+ISjgfyX51NB3hf3hVGs5KylOVja9kkQbbKV2gMqEt8 /7Rn/XLOYdoIT6VLZft8pkvwhcIByMm6gurM0mark2wIZVkP/1PIr31iAnC3dsfw Y6Oz+jQWexPbG/ZhI3Xx =KF+/ -----END PGP SIGNATURE----- --s84aUhKVeNw0gJU8e0EXo1qaHJSDc1hko--