Re: Import module with non-standard file name

2006-08-17 Thread Ben Finney
"Martin v. Löwis" <[EMAIL PROTECTED]> writes: > Ben Finney schrieb: > > Question: I have Python modules named without '.py' as the extension, > > and I'd like to be able to import them. How can I do that? > > I recommend to use imp.load_module. I've tried this; as Patrick Maupin alludes to, it c

Re: Import module with non-standard file name

2006-08-08 Thread Martin v. Löwis
Ben Finney schrieb: > Question: I have Python modules named without '.py' as the extension, > and I'd like to be able to import them. How can I do that? I recommend to use imp.load_module. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Import module with non-standard file name

2006-08-08 Thread Miki
Hello Ben, > Question: I have Python modules named without '.py' as the extension, > and I'd like to be able to import them. How can I do that? http://docs.python.org/lib/module-imp.html (hint: load_source :) HTH, Miki http://pythonwise.blogspot.com/ -- http://mail.python.org/mailman/listinfo/p

Re: Import module with non-standard file name

2006-08-07 Thread Ben Finney
"Patrick Maupin" <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > > Question: I have Python modules named without '.py' as the extension, > > and I'd like to be able to import them. How can I do that? > > This is a piece of cake in Python. > > >>> from types import ModuleType > >>> x = ModuleTy

Re: Import module with non-standard file name

2006-08-07 Thread Simon Forman
Ben Finney wrote: > Howdy all, > > Question: I have Python modules named without '.py' as the extension, > and I'd like to be able to import them. How can I do that? > > Background: > > On Unix, I write programs intended to be run as commands to a file > with no extension. This allows other program

Re: Import module with non-standard file name

2006-08-07 Thread Patrick Maupin
Ben Finney wrote: > Howdy all, > > Question: I have Python modules named without '.py' as the extension, > and I'd like to be able to import them. How can I do that? This is a piece of cake in Python. >>> from types import ModuleType >>> x = ModuleType('myModName') >>> data = open('myfilename').

Re: Import module with non-standard file name

2006-08-07 Thread Ben Finney
"John Machin" <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > > "John Machin" <[EMAIL PROTECTED]> writes: > > > If it can [modify sys.path], it can copy the MUT to some temp > > > directory, adding .py to the end of the name of the new file, > > > and put the temp directory in sys.path can'

Re: Import module with non-standard file name

2006-08-07 Thread John McMonagle
On Tue, 2006-08-08 at 11:06 +1000, Ben Finney wrote: > Howdy all, > > Question: I have Python modules named without '.py' as the extension, > and I'd like to be able to import them. How can I do that? > > Background: > > On Unix, I write programs intended to be run as commands to a file > with n

Re: Import module with non-standard file name

2006-08-07 Thread John Machin
Ben Finney wrote: > "John Machin" <[EMAIL PROTECTED]> writes: > > > Ben Finney wrote: > > > Now that I've got it written as a Python module, I'd like to write > > > unit tests for that module, which of course will need to import > > > the program module to test it. The unit test can explicitly add

Re: Import module with non-standard file name

2006-08-07 Thread Ben Finney
"John Machin" <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > > Now that I've got it written as a Python module, I'd like to write > > unit tests for that module, which of course will need to import > > the program module to test it. The unit test can explicitly add > > the directory where the p

Re: Import module with non-standard file name

2006-08-07 Thread John Machin
Ben Finney wrote: > Howdy all, > > Question: I have Python modules named without '.py' as the extension, > and I'd like to be able to import them. How can I do that? > > Background: > > On Unix, I write programs intended to be run as commands to a file > with no extension. This allows other progra

Import module with non-standard file name

2006-08-07 Thread Ben Finney
Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to be run as commands to a file with no extension. This allows other programs to use the command as an interf