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


Groups > comp.lang.python > #17823

Re: Get named module's file location

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>
Date 2011-12-24 06:52 +1100
Subject Re: Get named module's file location
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4038.1324669945.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Dec 24, 2011 at 6:40 AM, Gnarlodious <gnarlodious@gmail.com> wrote:
> [(imp.find_module(module)[1], os.path.getmtime(imp.find_module(module)[1])) for module in modules]
>
> Can I in some way assign imp.find_module(module)[1] to a variable and reuse it? Is this a job for lambda?

Well, you can use an additional comprehension to provide a temporary
variable, if you really want to do it all as a single expression.

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

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