Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Carl Banks
On Mar 31, 6:39 pm, Kay Schluehr wrote: > On 1 Apr., 00:38, Carl Banks wrote: > > > On Mar 31, 12:08 pm, Kay Schluehr wrote: > > > > > And your proposal is? > > > > I have still more questions than answers. > > > That's obvious. > > > Perhaps you should also refrain from making sweeping negative

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Carl Banks
On Mar 31, 12:08 pm, Kay Schluehr wrote: > > And your proposal is? > > I have still more questions than answers. That's obvious. Perhaps you should also refrain from making sweeping negative judgments about a system you have more questions than answers about. (Feel free to make sweeping negativ

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Kay Schluehr
On 1 Apr., 00:38, Carl Banks wrote: > On Mar 31, 12:08 pm, Kay Schluehr wrote: > > > > And your proposal is? > > > I have still more questions than answers. > > That's obvious. > > Perhaps you should also refrain from making sweeping negative > judgments about a system you have more questions tha

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Terry Reedy
Kay Schluehr wrote: On 31 Mrz., 20:50, Terry Reedy wrote: Although the ceremony has been performed basically correct the interpreter god is not pacified and doesn't respond. But the import 'ceremony' has not been performed. There is no import ceremony. Imports are just stated in the source

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Kay Schluehr
On 31 Mrz., 20:50, Terry Reedy wrote: > Nothing is added to sys.modules, except the __main__ module, unless > imported (which so are on startup). Yes. The startup process is opaque but at least user defined modules are not accidentally imported. > > > Although the ceremony has been performed >

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Terry Reedy
Kay Schluehr wrote: On 31 Mrz., 18:48, s4g wrote: This and similar solutions ( see Istvan Alberts ) point me to a fundamental problem of the current import architecture. Suppose you really want to run a module as a script without a prior import from a module path: ...A\B\C> python my_module.

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Kay Schluehr
On 31 Mrz., 18:48, s4g wrote: > Hi, > > I was looking for a nice idiom for interpackage imports as I found > this thread. > Here come a couple of solutions I came up with. Any discussion is > welcome. > > I assume the same file structure > > \ App > | main.py > +--\subpack1 > | | __init__.py > | |

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread s4g
Hi, I was looking for a nice idiom for interpackage imports as I found this thread. Here come a couple of solutions I came up with. Any discussion is welcome. I assume the same file structure \ App | main.py +--\subpack1 | | __init__.py | | module1.py | +--\subpack2 | | __init__.py | | module2.p

Re: Relative Imports, why the hell is it so hard?

2009-03-31 Thread Kay Schluehr
On 31 Mrz., 04:55, "Gabriel Genellina" wrote: > En Mon, 30 Mar 2009 21:15:59 -0300, Aahz escribió: > > > In article , > > Gabriel Genellina wrote: > > >> I'd recommend the oposite - use relative (intra-package) imports when > >> possible. Explicit is better than implicit - and starting with 2.7

Re: Relative Imports, why the hell is it so hard?

2009-03-30 Thread Gabriel Genellina
En Mon, 30 Mar 2009 21:15:59 -0300, Aahz escribió: In article , Gabriel Genellina wrote: I'd recommend the oposite - use relative (intra-package) imports when possible. Explicit is better than implicit - and starting with 2.7 -when "absolute" import semantics will be enabled by default- you'

Re: Relative Imports, why the hell is it so hard?

2009-03-30 Thread Aahz
In article , Gabriel Genellina wrote: > >I'd recommend the oposite - use relative (intra-package) imports when >possible. Explicit is better than implicit - and starting with 2.7 -when >"absolute" import semantics will be enabled by default- you'll *have* to >use relative imports inside a pa

Re: Relative Imports, why the hell is it so hard?

2009-03-25 Thread Carl Banks
On Mar 25, 1:07 am, Kay Schluehr wrote: > On 25 Mrz., 05:56, Carl Banks wrote: > > > > > > > On Mar 24, 8:32 pm, Istvan Albert wrote: > > > > On Mar 24, 9:35 pm, Maxim Khitrov wrote: > > > > > Works perfectly fine with relative imports. > > > > This only demonstrates that you are not aware of w

Re: Relative Imports, why the hell is it so hard?

2009-03-25 Thread Gabriel Genellina
En Tue, 24 Mar 2009 21:57:12 -0300, Istvan Albert escribió: On Mar 24, 3:16 pm, "Gabriel Genellina" wrote: Did you know, once a module is imported by the first time yeah yeah, could we not get sidetracked with details that are not relevant? what it obviously means is to import it in all of

Re: Relative Imports, why the hell is it so hard?

2009-03-25 Thread Kay Schluehr
On 25 Mrz., 05:56, Carl Banks wrote: > On Mar 24, 8:32 pm, Istvan Albert wrote: > > > On Mar 24, 9:35 pm, Maxim Khitrov wrote: > > > > Works perfectly fine with relative imports. > > > This only demonstrates that you are not aware of what the problem > > actually is. > > > Try using relative imp

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Carl Banks
On Mar 24, 8:32 pm, Istvan Albert wrote: > On Mar 24, 9:35 pm, Maxim Khitrov wrote: > > > Works perfectly fine with relative imports. > > This only demonstrates that you are not aware of what the problem > actually is. > > Try using relative imports so that it works when you import the module > i

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Istvan Albert
On Mar 24, 9:35 pm, Maxim Khitrov wrote: > Works perfectly fine with relative imports. This only demonstrates that you are not aware of what the problem actually is. Try using relative imports so that it works when you import the module itself. Now run the module as a program. The same module t

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Steve Holden
CinnamonDonkey wrote: > Top responses guys! This has all helped increadibly. > > Bearophile, > > My applogies if I have offended you, but: > > 1. "I can't know much about you from the start" - Is kind of my point. > Perhaps it would be better to avoid jumping to conclusions and pre- > judging so

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Maxim Khitrov
On Tue, Mar 24, 2009 at 8:57 PM, Istvan Albert wrote: > Does it not bother you that a module that uses relative imports cannot > be run on its own anymore? $ python --help -m mod : run library module as a script (terminates option list) $ python -m some.module.name Works perfectly fine with re

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Istvan Albert
On Mar 24, 3:16 pm, "Gabriel Genellina" wrote: > Did you know, once a module is imported by the first time yeah yeah, could we not get sidetracked with details that are not relevant? what it obviously means is to import it in all of your modules that need to access to relative paths > I don't u

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Gabriel Genellina
En Tue, 24 Mar 2009 09:01:01 -0300, R. David Murray escribió: CinnamonDonkey wrote: On 23 Mar, 18:57, bearophileh...@lycos.com wrote: > CinnamonDonkey: > > >what makes something a package? > > If you don't know what a package is, then maybe you don't need > packages. Thanx for taking the tim

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Gabriel Genellina
En Tue, 24 Mar 2009 12:49:08 -0300, Istvan Albert escribió: On Mar 23, 10:16 am, CinnamonDonkey wrote: I'm fairly new to Python so I still have a lot to learn. But I'd like to know how to correectly use relative imports. Relative imports are *fundamentally* broken in python. You will soon

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Istvan Albert
On Mar 23, 10:16 am, CinnamonDonkey wrote: > I'm fairly new to Python so I still have a lot to learn. But I'd like > to know how to correectly use relative imports. Relative imports are *fundamentally* broken in python. You will soon see that code using relative import will break if you attempt

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread CinnamonDonkey
Top responses guys! This has all helped increadibly. Bearophile, My applogies if I have offended you, but: 1. "I can't know much about you from the start" - Is kind of my point. Perhaps it would be better to avoid jumping to conclusions and pre- judging someones abilities simply because they are

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread bearophileHUGS
CinnamonDonkey: > It is neither constructive nor educational. > > It's a bit like saying "If you don't know what a function is, then > maybe you don't need it. ... have you tried having a single block of > code?" > > The point of people coming to these forums is to LEARN and share > knowledge. Perh

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread R. David Murray
Top posting corrected for clarity. CinnamonDonkey wrote: > On 23 Mar, 18:57, bearophileh...@lycos.com wrote: > > CinnamonDonkey: > > > > >what makes something a package? > > > > If you don't know what a package is, then maybe you don't need > > packages. > > > > In your project is it possible to

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Maxim Khitrov
On Tue, Mar 24, 2009 at 5:05 AM, CinnamonDonkey wrote: > Thanx Max - your explanation sorted it :-), and a big thank you to > everyone else also! > > >From the various posts, Python considers any directory containing the > __init__.py file to be a package. The top level package is the highest > di

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread CinnamonDonkey
Thanx Max - your explanation sorted it :-), and a big thank you to everyone else also! >From the various posts, Python considers any directory containing the __init__.py file to be a package. The top level package is the highest directory (closest to root) with a __init__.py file. Inter-package c

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread bearophileHUGS
CinnamonDonkey: >what makes something a package? If you don't know what a package is, then maybe you don't need packages. In your project is it possible to avoid using packages and just use modules in the same directory? Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread rocky
On Mar 23, 11:22 am, CinnamonDonkey wrote: > Hi Guys, > > Thanx for the quick responses, it is very much appreciated! > > Skip, that's a good point about "C++ != Python" and I assure you I am > very much aware of that ;-). > > Looking athttp://www.python.org/dev/peps/pep-0328/#guido-s-decision > w

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread Gabriel Genellina
En Mon, 23 Mar 2009 13:19:51 -0300, CinnamonDonkey escribió: My applogies if this is a silly question... but what makes something a package? A package is a directory with an __init__.py file [that Python is aware of]. and does that mean that what I am trying to do is not possible ? Y

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread Maxim Khitrov
On Mon, Mar 23, 2009 at 12:19 PM, CinnamonDonkey wrote: > My applogies if this is a silly question... but what makes something a > package? and does that mean that what I am trying to do is not > possible ? A package is a directory that has an __init__.py file. That file can be empty, or contain

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread CinnamonDonkey
My applogies if this is a silly question... but what makes something a package? and does that mean that what I am trying to do is not possible ? :( On 23 Mar, 15:53, "Gabriel Genellina" wrote: > En Mon, 23 Mar 2009 12:22:21 -0300, CinnamonDonkey   > escribió: > > > > >>     >> \ App > >>    

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread Gabriel Genellina
En Mon, 23 Mar 2009 12:22:21 -0300, CinnamonDonkey escribió:     >> \ App     >> |   main.py     >> +--\subpack1     >> |   |   __init__.py     >> |   |   module1.py     >> |     >> +--\subpack2     >> |   |   __init__.py     >> |   |   module2.py     >> Module1 needs to access functionality

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread Maxim Khitrov
On Mon, Mar 23, 2009 at 11:22 AM, CinnamonDonkey wrote: > Looking at http://www.python.org/dev/peps/pep-0328/#guido-s-decision > would suggest, unless I am completely miss-understanding the example, > that '.' refers to the current level and '..' pops up a level. That is correct, but you cannot j

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread CinnamonDonkey
Hi Guys, Thanx for the quick responses, it is very much appreciated! Skip, that's a good point about "C++ != Python" and I assure you I am very much aware of that ;-). Looking at http://www.python.org/dev/peps/pep-0328/#guido-s-decision would suggest, unless I am completely miss-understanding th

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread skip
>> Please, please... please! don't go off on rants about why you think >> relative imports should not be used. I've got 15+ years in C++ and >> relative inclusion of other sections of code has never been a >> problem. As far as I am concerned what I am trying to do is >> perfe

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread Maxim Khitrov
On Mon, Mar 23, 2009 at 10:16 AM, CinnamonDonkey wrote: > Hi All, > > I'm fairly new to Python so I still have a lot to learn. But I'd like > to know how to correectly use relative imports. > > Please, please... please! don't go off on rants about why you think > relative imports should not be use

Relative Imports, why the hell is it so hard?

2009-03-23 Thread CinnamonDonkey
Hi All, I'm fairly new to Python so I still have a lot to learn. But I'd like to know how to correectly use relative imports. Please, please... please! don't go off on rants about why you think relative imports should not be used. I've got 15+ years in C++ and relative inclusion of other sections