Re: relative imports and sub-module execution

2010-09-28 Thread Diez B. Roggisch
King writes: > Hi, > > After reading couple of docs and articles, I have implemented a simple > test package with nested modules. > When running "main.py", everything is working fine. Some of my sub- > modules has some small test routines for debug purpose. > It's because I am using relative pack

Re: relative imports with the __import__ function

2009-12-10 Thread Peter Otten
Chris Colbert wrote: > It seems the relative import level is dependent on the location of the > main entry module. I thought the whole idea of relative imports was to > make the import independent of the entry point? You don't have to specify it explicitly, so you can move a module containing fr

Re: relative imports with the __import__ function

2009-12-09 Thread Chris Colbert
On Tue, Dec 8, 2009 at 5:48 PM, Peter Otten <__pete...@web.de> wrote: > Chris Colbert wrote: > >> I have package tree that looks like this: >> >> main.py >> package >> __init__.py >> configuration.ini >> server >> __init__.py >> xmlrpc_server.py >> controller.py

Re: relative imports with the __import__ function

2009-12-08 Thread Peter Otten
Chris Colbert wrote: > I have package tree that looks like this: > > main.py > package > __init__.py > configuration.ini > server > __init__.py > xmlrpc_server.py > controller.py > reco > > segmentation > __init__.py > r

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

Re: Relative imports in Python 3.0

2008-12-17 Thread Kay Schluehr
On 17 Dez., 11:01, Nicholas wrote: > I am sure I am not the first to run into this issue, but what is the > solution? When you use 2to3 just uncomment or delete the file fix_import.py in lib2to3/fixes/ . -- http://mail.python.org/mailman/listinfo/python-list

Re: Relative imports in Python 3.0

2008-12-17 Thread Benjamin
On Dec 17, 4:01 am, Nicholas wrote: > Imagine a module that looks like > > ModuleDir >      __init__.py >      a.py >      b.py > > In python 2.x I used to have tests at the end of each of my modules, > so that module b.py might look something like > > import a >  .. >  .. > > if _

Re: Relative imports in Python 3.0

2008-12-17 Thread Brian Allen Vanderburg II
nicholas.c...@gmail.com wrote: Imagine a module that looks like ModuleDir __init__.py a.py b.py In python 2.x I used to have tests at the end of each of my modules, so that module b.py might look something like import a .. .. if __name__ == '__main__': run

Re: Relative imports and "import X as Y"

2008-09-02 Thread OKB (not okblacke)
Gabriel Genellina wrote: > En Sun, 31 Aug 2008 07:27:12 -0300, Wojtek Walczak > <[EMAIL PROTECTED]> escribió: > >> On Sun, 31 Aug 2008 06:40:35 GMT, OKB (not okblacke) wrote: >> Download the latest beta for your system and give it a try. >>> >>> Thanks for the advice, but I'd reall

Re: Relative imports and "import X as Y"

2008-09-02 Thread Gabriel Genellina
En Sun, 31 Aug 2008 07:27:12 -0300, Wojtek Walczak <[EMAIL PROTECTED]> escribió: > On Sun, 31 Aug 2008 06:40:35 GMT, OKB (not okblacke) wrote: > >>> Download the latest beta for your system and give it a try. >> >> Thanks for the advice, but I'd really rather not deal with >> installing the e

Re: Relative imports and "import X as Y"

2008-08-31 Thread Wojtek Walczak
On Sun, 31 Aug 2008 06:40:35 GMT, OKB (not okblacke) wrote: >> Download the latest beta for your system and give it a try. > > Thanks for the advice, but I'd really rather not deal with > installing the entire thing alongside my existing version, possibly > causing conflicts in who knows w

Re: Relative imports and "import X as Y"

2008-08-30 Thread OKB (not okblacke)
Terry Reedy wrote: > >> So, will relative imports in Python 3.0 allow things like >> "import >> ..relative.importing.path as prettyname"? If not, why not? > > Download the latest beta for your system and give it a try. Thanks for the advice, but I'd really rathe

Re: Relative imports and "import X as Y"

2008-08-30 Thread Terry Reedy
So, will relative imports in Python 3.0 allow things like "import ..relative.importing.path as prettyname"? If not, why not? Download the latest beta for your system and give it a try. -- http://mail.python.org/mailman/listinfo/python-list

Re: relative imports improve program organization... suggestions?

2008-08-13 Thread DG
Carl: Your solution is kind of what I was leaning towards after a bit of thinking. Since I have to have the modules each have their own detect() method, then it wouldn't be too hard to have their own test() method to put them through their paces. Catrironpi: I will look into this as it might hel

Re: relative imports improve program organization... suggestions?

2008-08-09 Thread castironpi
On Aug 8, 12:37 pm, DG <[EMAIL PROTECTED]> wrote: > Alright, I have searched and searched and read many conversations on > the topic of relative and absolute imports and am still not getting > the whole thing through my skull. > > Highlights of what I've > read:http://mail.python.org/pipermail/pyt

Re: Relative Imports

2007-07-17 Thread Scott David Daniels
Pat O'Hara wrote: > Hey guys, I know this is a really stupid question, but I've tried > googling and nothing came up. I also tried IRC, but it was too crowded > and I didn't get much useful information. > > I'm using Python 2.5 on WinXP, and I'm trying to do a relative import. > Here's the pack

Re: Relative imports

2005-03-05 Thread Kent Johnson
Chris wrote: After reading that link I tried to change my imports like this: " from .myPythonFileInTheSameFolder import MyClass" This style of import is not yet implemented. I'm getting more and more confused... How can I correctly do a relative import ? I think your choices are - keep doing what y

Re: Relative imports

2005-03-05 Thread Chris
After reading that link I tried to change my imports like this: " from .myPythonFileInTheSameFolder import MyClass" Well, this caused an error in PyLint: Encountered "." at line 1, column 6. Was expecting one of: "or" ... "and" ... "not" ... "is" ... "in" ... "lambda" ...

Re: Relative imports

2005-03-05 Thread Kent Johnson
Michael Hoffman wrote: Chris wrote: Why do relative imports cause warnings in PyLint? http://www.python.org/peps/pep-0328.html#rationale-for-absolute-imports I notice that this section says that from __future__ import absolute_import will be a feature of Python 2.4. Apparently it didn't make the

Re: Relative imports

2005-03-05 Thread Michael Hoffman
Chris wrote: Why do relative imports cause warnings in PyLint? http://www.python.org/peps/pep-0328.html#rationale-for-absolute-imports -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list