Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109092
| From | Gerald Britton <gerald.britton@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Question about imports and packages |
| Date | 2016-05-24 19:35 -0400 |
| Message-ID | <mailman.70.1464132967.20402.python-list@python.org> (permalink) |
| References | <CAPxRSnYXQL-0zTo81_QmhXan6nJ-fzCBpS6y5DjqS952SV=yjg@mail.gmail.com> |
I'm trying to understand packages in Python, especially Intra Package
References.
>From https://docs.python.org/2/tutorial/modules.html#packages i see that:
you can use absolute imports to refer to submodules of siblings packages.
This is what I can't get to work in my case. Here's the setup:
directory testpkg containing three files:
1. an empty __init__.py
2. a testimport.py which has:
from testpkg.testimported import A
a = A()
print type(a)
3. a testimported.py which has:
class A():
pass
When I run
python testimport.py
I get:
Traceback (most recent call last):
File "testimport.py", line 1, in <module>
from testpkg.testimported import A
ImportError: No module named testpkg.testimported
However, I thought I was doing what the doc describes for intra package
imports. What am I missing?
Or is the problem simply that I do not have subpackages?
--
Gerald Britton
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Question about imports and packages Gerald Britton <gerald.britton@gmail.com> - 2016-05-24 19:35 -0400
Re: Question about imports and packages Steven D'Aprano <steve@pearwood.info> - 2016-05-25 11:02 +1000
Re: Question about imports and packages Terry Reedy <tjreedy@udel.edu> - 2016-05-24 23:36 -0400
csiph-web