[Tutor] Import package module problem
mandel at themacaque.com
mandel at themacaque.com
Tue May 12 10:33:21 CEST 2009
> Le Tue, 12 May 2009 08:37:27 +0100 (BST),
> mandel at themacaque.com s'exprima ainsi:
>
>> Lets see if I understand what you mean, in my example I should add an
>> import inside __init__.py to be able to use relative imports:
>>
>> /general
>> __init__.py >> from address_book import AddressBook
>> address_book.py
>> /groups
>> __init__.py >> from contact_group import ContactGroup
>> contact_group.py
>>
>> Lets say I have the above, would I be able to use the following?
>>
>> from ..groups.contact_group import ContactGroup
>>
>> I'm trying to use this type of import to be able to bundle my unit tests
>> with my code and let devels work with it. I have read somewhere that
>> __all__ can do the trick but it did not say how.
>
> Have you tried it?
>
> Denis
> ------
> la vita e estrany
>
Yes I have tried and I keep getting the following ValueError:
ValueError: Attempted relative import in non-package
I have tried with my code, do you have an example or yours that works that
way? I might have not done it worng (I hope I haven't)
Kr,
Manuel
More information about the Tutor
mailing list