Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100515

Re: does the order in which the modules are placed in a file matters ?

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: does the order in which the modules are placed in a file matters ?
Date 2015-12-17 03:14 +1100
Message-ID <mailman.13.1450282457.30845.python-list@python.org> (permalink)
References <CACT3xuW5hdCUDaO4i-Fd8583j9CC0ATm3xHWYsqEXcbuW8_pgw@mail.gmail.com>

Show all headers | View raw


On Thu, Dec 17, 2015 at 3:09 AM, Ganesh Pal <ganesh1pal@gmail.com> 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
>
> order while writing the program
>
> For Example
>
> import os
> import shlex
> import subprocess
> import time
> import sys
> import logging
> import  plaftform.cluster
> from util import run

The order of the import statements is the order the modules will get
loaded up. As a general rule this won't matter; when it comes to
standard library modules, you can generally assume that you can put
them in any order without it making any difference. It's common to
order them in some aesthetically-pleasing way (maybe alphabetical
order, or maybe sort them by the length of the name - whatever you
like).

There is a broad convention that standard library modules get imported
first, and modules that are part of the current project get imported
afterwards. But even that doesn't usually matter very much.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: does the order in which the modules are placed in a file matters ? Chris Angelico <rosuav@gmail.com> - 2015-12-17 03:14 +1100

csiph-web