Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dan Strohl Newsgroups: comp.lang.python Subject: RE: does the order in which the modules are placed in a file matters ? Date: Wed, 16 Dec 2015 16:42:01 +0000 Lines: 80 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de zYdaIchOXv+6yJVujOFOnwZbumKz+P9Eq5BbzCTKk+zw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'sys': 0.05; 'subject:file': 0.07; 'wednesday,': 0.07; 'cc:addr:python-list': 0.09; 'imported': 0.09; 'statements': 0.09; 'subject:modules': 0.09; 'subject:which': 0.09; 'python': 0.10; 'assume': 0.11; '2.7': 0.13; 'message-----': 0.15; 'thu,': 0.15; '"*"': 0.16; 'alphabetical': 0.16; 'doing:': 0.16; 'modules,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:[ 50': 0.16; 'subject:matters': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; 'duplicate': 0.18; 'have:': 0.18; 'library': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'first,': 0.20; 'referring': 0.22; 'see:': 0.22; 'am,': 0.23; '(or': 0.23; 'dec': 0.23; 'this:': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; "doesn't": 0.26; 'example': 0.26; 'linux': 0.26; 'chris': 0.26; 'logging': 0.27; '(maybe': 0.29; 'dan': 0.29; 'received:192.168.10': 0.29; 'url:mailman': 0.30; 'convention': 0.30; 'another': 0.32; 'up.': 0.32; 'december': 0.32; 'generally': 0.32; 'maybe': 0.33; 'run': 0.33; 'class': 0.33; 'url:python': 0.33; 'common': 0.33; 'usually': 0.33; 'done,': 0.33; 'foo': 0.33; 'rule': 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'file': 0.34; 'sent:': 0.35; 'cc:': 0.35; 'subject:': 0.35; 'but': 0.36; 'project': 0.36; 'there': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.36; 'loaded': 0.36; 'modules': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; "won't": 0.38; 'names': 0.38; 'end': 0.39; 'whatever': 0.39; 'does': 0.39; 'subject:the': 0.39; 'from:': 0.39; 'received:192': 0.39; 'url:mail': 0.40; 'called': 0.40; 'some': 0.40; 'making': 0.62; 'course': 0.62; 'matter': 0.63; 'more': 0.63; 'information': 0.63; 'packages,': 0.66; 'python-list': 0.66; 'email name:python-list': 0.67; 'situation': 0.67; 'approaches': 0.72; 'gotten': 0.76; 'as:': 0.79; 'chrisa': 0.84; 'difference.': 0.84; 'intending': 0.84; 'received:192.168.15': 0.84; 'url:tutorial': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=f5.com; i=@f5.com; q=dns/txt; s=seattle; t=1450284192; x=1481820192; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=QnxL2A8XVoyVtDfwqX2VoL78+X/oyPEDanI2VTjA35M=; b=iruJSv4qcC6YJeiS9Pmbjpupnt/fYyIMomzZ+wj97/X74dWYShMM9G2H HUWe8SaLB205r4I7swi50twU5F43I352CW2JNFYG2hOnYprFVNW7XR2iv C6g4wM7Wk0QDwEmfz8WHieNPiXHeNk7AJrzJY9ftZx7rQgpPqGH6euF67 4=; X-IronPort-AV: E=McAfee;i="5700,7163,8016"; a="193051998" X-IronPort-AV: E=Sophos;i="5.20,437,1444694400"; d="scan'208";a="193051998" Thread-Topic: does the order in which the modules are placed in a file matters ? Thread-Index: AQHROBxPVZDhA/g3UkO8inc4HULrvZ7OT3qA//98FFA= In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [192.168.15.239] 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:100521 For the general modules it doesn't matter, however using if you are using a= ny non-standard packages, and If there are duplicate names in any of the mo= dules and if you import them with a "*" (as some packages suggest), it can = cause you to end up referring to an object you were not intending to. For example, if you have found a package called "foo", and the instructions= on it are to import it as: from foo import * Then you have another package called "bar" with the same instructions... so= now you have: from foo import * from bar import * In both of these there is a class called "snafu", when you do this: from foo import * from bar import * SITUATION =3D snafu() You are going to get bar.snafu(), not foo.snafu() This can of course be gotten around by doing: import foo import bar SITUATION =3D foo.snafu() (or a number of other approaches using "as" etc...) Note, using * is dis-recommended, though pretty often done, for more inform= ation on using *, see: https://docs.python.org/2/tutorial/modules.html#impo= rting-from-a-package=20 Dan Strohl -----Original Message----- From: Python-list [mailto:python-list-bounces+d.strohl=3Df5.com@python.org]= On Behalf Of Chris Angelico Sent: Wednesday, December 16, 2015 8:14 AM Cc: python-list@python.org Subject: Re: does the order in which the modules are placed in a file matte= rs ? On Thu, Dec 17, 2015 at 3:09 AM, Ganesh Pal wrote: > Iam on python 2.7 and linux .I need to know if we need to place the=20 > 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 witho= ut it making any difference. It's common to order them in some aestheticall= y-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 firs= t, and modules that are part of the current project get imported afterwards= . But even that doesn't usually matter very much. ChrisA -- https://mail.python.org/mailman/listinfo/python-list