Py3: Import relative path module

MRAB python at mrabarnett.plus.com
Tue Nov 2 22:29:30 EDT 2010


On 03/11/2010 01:48, Gnarlodious wrote:
> I admit I don't understand any of what was said here. Or why it is so
> hard what I am trying to do. I searched Google for a few hours looking
> for a way to import a module from an absolute path, but that was a
> waste of time too.
>
> To reiterate, I am trying to import a Def function from a file one
> level up. Let's say relative import is unreasonable to expect from
> Python. If it is possible using an absolute path, please let me know
> how, in plain language. Otherwise I can continue to copy and paste my
> programming into several files.
>
> Thank you for any help.
>
After some experimentation (and Googling!) I think the problem is that
a module can do your relative import but a main script can't.

Or, to put it another way, if __name__ is "__main__" then it won't work.



More information about the Python-list mailing list