Py3: Import relative path module

Terry Reedy tjreedy at udel.edu
Mon Nov 1 15:54:53 EDT 2010


On 11/1/2010 6:54 AM, Gnarlodious wrote:
> On Nov 1, 2:16 am, Steven D'Aprano<steve-REMOVE-
> T... at cybersource.com.au>  wrote:
>> On Mon, 01 Nov 2010 01:08:52 -0700, Gnarlodious wrote:
>>> On Oct 31, 11:09 am, Дамјан Георгиевски wrote:
>>>> from .. import Data.DumpHT as DumpHT
>>
>>> That doesn't work. Any more ideas?
>>
>> Define "doesn't work".
>
> LOL.
> I get error:
>
>      from .. import Data.DumpHT as DumpHT
>                         ^
> SyntaxError: invalid syntax
>
> Rewording gets me closer:
>
>      from ..Data import DumpHT
> ValueError: Attempted relative import in non-package
>
> I do have the empty __init__.py file in the Data folder. What is
> wrong?

What about the folder above it?

As far as I know, the main reason to use relative imports is if you have 
a subpackage that you expect to use within more then one package. 
Otherwise, it is usually a lot easier to use absolute imports starting 
with the top-level package.

-- 
Terry Jan Reedy





More information about the Python-list mailing list