Re: Importing by file name

2013-11-24 Thread Mark Lawrence
On 24/11/2013 14:15, Steven D'Aprano wrote: That was the case up to 3.3, but Python 3.4 has the import machinery re- written in pure Python (except for a tiny bit of bootstrapping machinery, if I understand correctly). I understand that nobody understood the import machinery in full (although th

Re: Importing by file name

2013-11-24 Thread Chris Angelico
On Mon, Nov 25, 2013 at 1:15 AM, Steven D'Aprano wrote: > On Sun, 24 Nov 2013 19:07:38 +1100, Chris Angelico wrote: > >> I know the recent Pythons give a lot of import power to the script. But >> maybe I'm just asking too much, and some of this stuff really is magical >> and implemented in C? > >

Re: Importing by file name

2013-11-24 Thread Steven D'Aprano
On Sun, 24 Nov 2013 19:07:38 +1100, Chris Angelico wrote: > I know the recent Pythons give a lot of import power to the script. But > maybe I'm just asking too much, and some of this stuff really is magical > and implemented in C? That was the case up to 3.3, but Python 3.4 has the import machine

Re: Importing by file name

2013-11-24 Thread Ian Kelly
On Sun, Nov 24, 2013 at 4:05 AM, Chris Angelico 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 importl

Re: Importing by file name

2013-11-24 Thread Chris Angelico
On Sun, Nov 24, 2013 at 8:50 PM, Ian Kelly wrote: > On Sun, Nov 24, 2013 at 2:18 AM, Christian Gollwitzer wrote: >> Am 24.11.13 04:41, schrieb Chris Angelico: >> >>> As part of a post on python-ideas, I wanted to knock together a quick >>> little script that "imports" a file based on its name, in

Re: Importing by file name

2013-11-24 Thread Ian Kelly
On Sun, Nov 24, 2013 at 2:18 AM, Christian Gollwitzer wrote: > Am 24.11.13 04:41, schrieb Chris Angelico: > >> As part of a post on python-ideas, I wanted to knock together a quick >> little script that "imports" a file based on its name, in the same way >> that the Python interpreter will happily

Re: Importing by file name

2013-11-24 Thread Christian Gollwitzer
Am 24.11.13 04:41, schrieb Chris Angelico: As part of a post on python-ideas, I wanted to knock together a quick little script that "imports" a file based on its name, in the same way that the Python interpreter will happily take an absolute pathname for the main script. Is it imp.load_source()

Re: Importing by file name

2013-11-24 Thread Chris Angelico
On Sun, Nov 24, 2013 at 7:00 PM, Ian Kelly wrote: > The importer mechanism as far as I know only accepts module names, not > filesystem paths; I believe this is by design. You could imitate it by > doing something like this: > > import imp > import sys > > mod = imp.new_module('spam') > exec(open

Re: Importing by file name

2013-11-24 Thread Ian Kelly
On Nov 23, 2013 9:42 PM, "Chris Angelico" wrote: > As part of a post on python-ideas, I wanted to knock together a quick > little script that "imports" a file based on its name, in the same way > that the Python interpreter will happily take an absolute pathname for > the main script. I'm sure th

Re: Importing by file name

2013-11-23 Thread Devin Jeanpierre
On Sat, Nov 23, 2013 at 7:41 PM, Chris Angelico wrote: > As part of a post on python-ideas, I wanted to knock together a quick > little script that "imports" a file based on its name, in the same way > that the Python interpreter will happily take an absolute pathname for > the main script. I'm su

Importing by file name

2013-11-23 Thread Chris Angelico
As part of a post on python-ideas, I wanted to knock together a quick little script that "imports" a file based on its name, in the same way that the Python interpreter will happily take an absolute pathname for the main script. I'm sure there's a way to do it, but I don't know how. Obviously the i