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


Groups > comp.lang.python > #17826

Re: Get named module's file location

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:module': 0.04; 'python': 0.08; "(it's": 0.09; 'brackets': 0.09; 'read.': 0.10; 'am,': 0.12; 'skip:[ 20': 0.12; 'subject:file': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'expression,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guessing': 0.16; 'iterates': 0.16; 'parentheses': 0.16; 'subject:named': 0.16; 'meant': 0.17; 'wrote:': 0.18; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'sat,': 0.25; 'module': 0.26; "i'm": 0.26; 'do.': 0.28; 'version,': 0.28; 'message-id:@mail.gmail.com': 0.28; '24,': 0.29; 'idle': 0.29; 'temporary': 0.29; 'modules,': 0.30; 'separately': 0.30; 'chris': 0.30; 'equivalent': 0.31; 'skip:( 20': 0.31; 'does': 0.32; 'list': 0.32; "won't": 0.33; 'actually': 0.33; 'instead': 0.33; 'that,': 0.33; 'to:addr:python- list': 0.34; 'calling': 0.34; 'list.': 0.35; 'two': 0.37; 'but': 0.37; 'list,': 0.37; 'received:google.com': 0.37; 'hoping': 0.38; 'received:209.85': 0.38; 'skip:o 20': 0.38; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'once': 0.60; 'more': 0.61; '2011': 0.61; 'full': 0.62; 'results': 0.63; 'square': 0.67; 'subject:Get': 0.71; 'saving': 0.76; 'each,': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=kifyL69O4GI9aEaMDa2ApBWYbLJ5QnZPMZi1+M3gh3s=; b=R7tacz824AA+ETOWeHkQGJT0Kr5d6xg27LcuTQPTsLWr14N/CHUKAcXg4cbjrte30b fINdmid7DUiagzIKwsjTUyPa1Uwh0eyV6Pah6M9g9+qUm9E6wZbG5yRFwB20PD+f86hp HF4E+3PJyJTht8WHIqBOCKGVR+gfqoG4nEgK4=
MIME-Version 1.0
In-Reply-To <32191702.960.1324675017428.JavaMail.geo-discussion-forums@prmw6>
References <32472953.855.1324656114851.JavaMail.geo-discussion-forums@prix23> <roy-533975.11181223122011@news.panix.com> <4946660.379.1324659073535.JavaMail.geo-discussion-forums@prez5> <roy-4780C2.11564723122011@news.panix.com> <4652751.858.1324669248908.JavaMail.geo-discussion-forums@prj1> <mailman.4038.1324669945.27778.python-list@python.org> <32191702.960.1324675017428.JavaMail.geo-discussion-forums@prmw6>
Date Sat, 24 Dec 2011 08:21:56 +1100
Subject Re: Get named module's file location
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4040.1324675319.27778.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324675319 news.xs4all.nl 6934 [2001:888:2000:d::a6]:37128
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17826

Show key headers only | View raw


I'm guessing you meant for this to be on-list, and am hoping you don't
mind that I'm replying on-list.

On Sat, Dec 24, 2011 at 8:16 AM, Gnarlodious <gnarlodious@gmail.com> wrote:
> Chris Angelico wrote:
>> [(m, os.path.getmtime(m)) for m in (imp.find_module(module)[1] for
>> module in modules)]
>>
>> Yeah, a little hard to read. Tell me, does this formulation execute
>> imp.find_module(module) once or twice for each modname?

What this does is save a temporary list, more or less. (It's actually
a generator expression, not a list comprehension, but that's
immaterial.)

temporary = [imp.find_module(module)[1] for module in modules]
[(m, os.path.getmtime(m)) for m in temporary]

It iterates over modules, calling find_module for each, and saving the
results to a new list. Then separately iterates over the new list,
pairing each with the getmtime.

Since I used parentheses instead of square brackets in the original
expression, Python won't actually build the full list. Other than
that, it's equivalent to the two-statement version, and you can try
those two in IDLE to see what they do.

ChrisA

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


Thread

Get named module's file location Gnarlodious <gnarlodious@gmail.com> - 2011-12-23 08:01 -0800
  Re: Get named module's file location Roy Smith <roy@panix.com> - 2011-12-23 11:18 -0500
    Re: Get named module's file location Gnarlodious <gnarlodious@gmail.com> - 2011-12-23 08:51 -0800
      Re: Get named module's file location Roy Smith <roy@panix.com> - 2011-12-23 11:56 -0500
        Re: Get named module's file location Gnarlodious <gnarlodious@gmail.com> - 2011-12-23 11:40 -0800
          Re: Get named module's file location Chris Angelico <rosuav@gmail.com> - 2011-12-24 06:52 +1100
            Re: Get named module's file location Chris Angelico <rosuav@gmail.com> - 2011-12-24 08:21 +1100
          Re: Get named module's file location Roy Smith <roy@panix.com> - 2011-12-23 15:00 -0500
            Re: Get named module's file location Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-23 22:39 +0000

csiph-web