Re: Question about imports and packages

2016-05-25 Thread Chris Angelico
On Wed, May 25, 2016 at 6:27 PM, Steven D'Aprano wrote: > I don't think this is that much different from the way other scripting > languages handle it. E.g. bash. If I have a set of (say) shell scripts: > > fnord/ > +-- foo.sh > +-- bar.sh > > > where foo.sh

Re: Question about imports and packages

2016-05-25 Thread Steven D'Aprano
On Wednesday 25 May 2016 14:39, Ben Finney wrote: > What the Python import system expects you to do is:: > > cd ../ > python3 -m fnord.foo I don't think you even need to do the cd provided the fnord directory is inside a directory on the path. It only gets complicated if fnord cannot be found

Re: Question about imports and packages

2016-05-24 Thread Ben Finney
Gerald Britton writes: > On Wed, 25 May 2016 10:00 am, Steven D'Aprano wrote: > >The problem is that you are running the Python script from *inside* > >the package. That means, as far as the script can see, there is no > >longer a package visible -- it cannot see its

Re: Question about imports and packages

2016-05-24 Thread Terry Reedy
On 5/24/2016 9:02 PM, Steven D'Aprano wrote: On Wed, 25 May 2016 09:35 am, Gerald Britton wrote: For brevity, here's your package setup: testpkg/ +-- __init__.py +-- testimport.py which runs "from testpkg.testimported import A" +-- testimported.py containing class A Your package layout is

Question about imports and packages

2016-05-24 Thread Gerald Britton
On Wed, 25 May 2016 10:00 am, Steven D'Aprano wrote: >On Wed, 25 May 2016 09:35 am, Gerald Britton wrote: > >For brevity, here's your package setup: > > >testpkg/ >+-- __init__.py >+-- testimport.py which runs "from testpkg.testimported import A" >+-- testimported.py containing class A > >Your

Re: Question about imports and packages

2016-05-24 Thread Steven D'Aprano
On Wed, 25 May 2016 09:35 am, Gerald Britton wrote: For brevity, here's your package setup: testpkg/ +-- __init__.py +-- testimport.py which runs "from testpkg.testimported import A" +-- testimported.py containing class A Your package layout is correct. But: > When I run > > python

Question about imports and packages

2016-05-24 Thread Gerald Britton
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: