Re: Import a module from a specific file path

2014-11-21 Thread Ben Finney
Chris Angelico writes: > So can you simply: > > $ python -m foo.fooprog > > ? (or 'python3', either way) So, that's a pretty awful user interface. (The file is named ‘fooprog’ because it's an executable, intended to be run directly at the command line.) That solution would be rather inferior to

Re: Import a module from a specific file path

2014-11-21 Thread Marko Rauhamaa
Ben Finney : > Solutions usually seem to entail contortions of cluttering the import > block by discovering the current path, and fussing around with > ‘sys.path’, before finally doing the import:: > > #! /usr/bin/python3 > > import sys > import os.path > > program_dir = os.path.di

Re: Import a module from a specific file path (was: PyWart: "Python's import statement and the history of external dependencies")

2014-11-21 Thread Chris Angelico
On Sat, Nov 22, 2014 at 11:37 AM, Ben Finney wrote: > I don't think I'd ever want to specify an absolute file path for the > module. But it would make my Python life immeasurably better if I could > specify *relative* file paths for importing a module. > > Allowing relative paths makes this portab

Import a module from a specific file path (was: PyWart: "Python's import statement and the history of external dependencies")

2014-11-21 Thread Ben Finney
ther than the one it was built on? Allowing relative paths makes this portable, so long as the application's relative tree structure is maintained. > There are a VERY VERY few cases where you really do want to import a > module from a specific file path. For those situations, there ar