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


Groups > comp.lang.python > #60362

Re: Importing by file name

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.041
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'none:': 0.07; 'subject:file': 0.07; '24,': 0.16; 'for,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'seems': 0.21; 'import': 0.22; 'planned': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work:': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'explains': 0.36; "didn't": 0.36; 'nov': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'it!': 0.67; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=kPPKrV4f+BhRXnUoBD5PXE9juTEmkJPJFBavxrBzm5Y=; b=ThTSPlrhfAZX1RzGiqm7/LdDEJDvcNNzZPXbH3fT7pdaogNRjarRqq7ydq1mo5Ayn6 71AGDS/33c8z3b1xDzpuWHHAp+CHAbzyhwH4Z0ONHuj8URP65uaQJB9/Pm/oZPanFXka 5T/lvhy2z3pqg9LXnYI42LQw2PuJ5XA+t/Fgx87yHxd7AQf5NMOoIZ2UIkzxJOFt57SM NLN6H4UI5rl5/l384MvB8sm+kHGkH9r+rL2Lp/LuC5G5j5PutLXDQv+hW3wllPe32fEt PnO+19GTfvM2f/BRQ9kfIXYkVXwqAdqPrrMNw359bDymSss7mayp8HyueWvBCFPa1XqB EZAg==
X-Received by 10.68.227.36 with SMTP id rx4mr2244552pbc.128.1385293060912; Sun, 24 Nov 2013 03:37:40 -0800 (PST)
MIME-Version 1.0
In-Reply-To <CAPTjJmrJOwyg-9_qESA0temJUzWw2zt9T2qnXMb4QK8ZHNWk0g@mail.gmail.com>
References <mailman.3114.1385264464.18130.python-list@python.org> <l6sg89$bns$1@dont-email.me> <CALwzidmbQ8bOxZM6kfRe=z0i2S=srUs5tZ7feofCVL+0JKA7Mg@mail.gmail.com> <CAPTjJmrJOwyg-9_qESA0temJUzWw2zt9T2qnXMb4QK8ZHNWk0g@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Sun, 24 Nov 2013 04:37:00 -0700
Subject Re: Importing by file name
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3126.1385293064.18130.python-list@python.org> (permalink)
Lines 13
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385293064 news.xs4all.nl 15890 [2001:888:2000:d::a6]:38628
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60362

Show key headers only | View raw


On Sun, Nov 24, 2013 at 4:05 AM, Chris Angelico <rosuav@gmail.com> wrote:
> Undocumented... that explains why I didn't know about it! But that
> does appear to be what I'm looking for, so is there some equivalent
> planned as a replacement?

Hmm, playing around with importlib a bit, this seems to work:

from importlib import find_loader
loader = find_loader('spam', ['/path/to'])
if loader is not None:
    module = loader.load_module()

The path passed to find_loader is searched instead of sys.path.

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


Thread

Importing by file name Chris Angelico <rosuav@gmail.com> - 2013-11-24 14:41 +1100
  Re: Importing by file name Christian Gollwitzer <auriocus@gmx.de> - 2013-11-24 10:18 +0100
    Re: Importing by file name Ian Kelly <ian.g.kelly@gmail.com> - 2013-11-24 02:50 -0700
    Re: Importing by file name Chris Angelico <rosuav@gmail.com> - 2013-11-24 22:05 +1100
    Re: Importing by file name Ian Kelly <ian.g.kelly@gmail.com> - 2013-11-24 04:37 -0700

csiph-web