How does the import machinery handle relative imports?

2020-04-22 Thread Adam Preble
I'm fussing over some details of relative imports while trying to mimic Python module loading in my personal project. This is getting more into corner cases, but I can spare time to talk about it while working on more normal stuff. I first found this place: https://manikos.github.io/how-py

Re: Python programs and relative imports

2016-04-08 Thread Ian Kelly
On Fri, Apr 8, 2016 at 11:50 AM, Rob Gaddi wrote: > Sort of. If I've got a directory full of files (in a package) > that I'm working on, the relative import semantics change based on > whether I'm one directory up and importing the package or in the same > directory and importing the files locall

Re: Python programs and relative imports

2016-04-08 Thread Chris Angelico
On Sat, Apr 9, 2016 at 3:50 AM, Rob Gaddi wrote: > Sort of. If I've got a directory full of files (in a package) > that I'm working on, the relative import semantics change based on > whether I'm one directory up and importing the package or in the same > directory and importing the files locally

Re: Python programs and relative imports

2016-04-08 Thread Rob Gaddi
Chris Angelico wrote: > On Sat, Apr 9, 2016 at 2:59 AM, Rob Gaddi > wrote: >> Rob Gaddi wrote: >> >>> Does anyone know the history of why relative imports are only available >>> for packages and not for "programs"? It certainly complicates life. >

Re: Python programs and relative imports

2016-04-08 Thread Chris Angelico
On Sat, Apr 9, 2016 at 2:59 AM, Rob Gaddi wrote: > Rob Gaddi wrote: > >> Does anyone know the history of why relative imports are only available >> for packages and not for "programs"? It certainly complicates life. >> > > Really, no one? It seems like

Re: Python programs and relative imports

2016-04-08 Thread Rob Gaddi
Rob Gaddi wrote: > Does anyone know the history of why relative imports are only available > for packages and not for "programs"? It certainly complicates life. > Really, no one? It seems like a fairly obvious thing to have included; all of the reasons that you want to be

Python programs and relative imports

2016-04-04 Thread Rob Gaddi
Does anyone know the history of why relative imports are only available for packages and not for "programs"? It certainly complicates life. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.

Re: Incompatible idioms: relative imports, top-level program file

2015-02-10 Thread Rustom Mody
On Sunday, February 8, 2015 at 3:52:19 AM UTC+5:30, Gregory Ewing wrote: > Rustom Mody wrote: > > Wanted to try out sympy. > > apt-install promised ź GB download, ž GB space usage > > > > Just getting a src-tarball was: 6M download, 30M after opening the tar. > > Have you actually tried compiling

Re: Incompatible idioms: relative imports, top-level program file

2015-02-07 Thread Gregory Ewing
Rustom Mody wrote: Wanted to try out sympy. apt-install promised ¼ GB download, ¾ GB space usage Just getting a src-tarball was: 6M download, 30M after opening the tar. Have you actually tried compiling and using that tarball, though? Sympy hooks into a lot of other libraries that are themsel

Re: Incompatible idioms: relative imports, top-level program file

2015-02-06 Thread Rustom Mody
On Saturday, February 7, 2015 at 8:43:44 AM UTC+5:30, Rustom Mody wrote: > There is on the one hand python modules/packages mechanism with all the > hell of dozens of incompatible versions of setuptools/distribute/distutils > etc. > > On the other there is the OS-specific practices/policy such a

Re: Incompatible idioms: relative imports, top-level program file

2015-02-06 Thread Rustom Mody
x27;s no need to explose those in a > > > site package, they normally only need to be local to the > > > application. > > > > If they are not in the Python module path, how are they imported at > > all? > > Only absolute imports use the module search path. The

Re: Incompatible idioms: relative imports, top-level program file

2015-02-06 Thread Ben Finney
he > > application. > > If they are not in the Python module path, how are they imported at > all? Only absolute imports use the module search path. The whole point of relative imports is to import a module within the same (or a sub-) package, without modifying the search path.

Re: Incompatible idioms: relative imports, top-level program file

2015-02-06 Thread Ethan Furman
rts is for libraries [1], and libraries must be in sys.path. Are you saying that after placing your top-level file's path in sys.path, that relative imports do not work? -- ~Ethan~ [1] which can be a single module signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list

Incompatible idioms: relative imports, top-level program file (was: Setuptools, __init__ and __main__)

2015-02-06 Thread Ben Finney
ity that its implementation occupies several sub-modules. There's no need to explose those in a site package, they normally only need to be local to the application. So the correct idiom is ‘from __future__ import absolute_import’ and keep the application's own implementation

nosetests vs. relative imports?

2013-12-24 Thread Roy Smith
Environment: Ubuntu Linux 12.04 (precise) Python 2.7.3 I have a package (i.e. a directory with a __init__.py file). In that directory, I have files math.py and test_math.py; test_math.py contains the single line: from .math import EMA If I run on the command line, "nosetests test_math.py" eve

python 2.x and python 3 relative imports and

2013-11-26 Thread ptomulik
ort pkg3 import pkg1.pk2.pk3.foo but this clutters local (bar) namespace with symbols 'foo' (first case) or 'pkg1' (second approach). Do you know any other way for relative imports to achieve exactly same effect as with old import semantics? -- https://mail.python.org/mailman/listinfo/python-list

Re: Understanding relative imports in package - and running pytest with relative imports?

2013-11-24 Thread Devin Jeanpierre
On Sun, Nov 24, 2013 at 5:30 PM, Victor Hooi wrote: > The advice seems to be either to run it from the parent directory of > furniture with: > > python -m furniture.chair.build_chair Yes. More pedantically, run it from somewhere such that the furniture package is importable. For example, if

Understanding relative imports in package - and running pytest with relative imports?

2013-11-24 Thread Victor Hooi
ath that. build_chair.py and build_table.py are supposed to import from common/shared.py using relative imports. e.g.: from ..common.shared import supplies However, if you then try to run the scripts build_chair.py, or build_table.py, they'll complain about: ValueError: Attempted

Relative imports in packages

2012-11-09 Thread Johannes Bauer
Hi list, I've these two minor problems which bothered me for quite some time, maybe you can help me. I'm using Python 3.2. For some project I have a component in its own package. Let's say the structure looks like this: pkg/__init__.py pkg/Foo.py pkg/Bar.py Foo.py and Bar.py contain their class

Dynamic imports + relative imports in Python 3

2011-02-22 Thread zildjohn01
This is a copy-paste of a StackOverflow question. Nobody answered there, but I figured I might have better luck here. I have a Python 3 project where I'm dynamically importing modules from disk, using `imp.load_module`. But, I've run into an problem where relative imports fail, when th

Re: relative imports and sub-module execution

2010-09-28 Thread Diez B. Roggisch
27; individually. It's giving an error: > > ImportError: No module named core.folder2 > > Is this mean when you have created a package where modules are using > relative imports, they can't execute individually? The problem is your python-path. Python will put the path of the s

relative imports and sub-module execution

2010-09-27 Thread King
f2b.py in folder2/f2b.py, I am importing from core.folder1 import f1a print f1a.myvar Now I can't execute 'f2b.py' individually. It's giving an error: ImportError: No module named core.folder2 Is this mean when you have created a package where modules are using relative impor

Re: Problems with relative imports and pep 366

2010-06-01 Thread Jean-Michel Pichavant
network/ __init__.py clientlib.py server.py - gui/ __init__.py mainwindow.py controllers.py In this structure, for example modules contained in each package may want to access the helpers utilities through relative imports in something like: # network/clientlib.py f

Problems with relative imports and pep 366

2010-05-31 Thread Gabriele Lanaro
it__.py clientlib.py server.py - gui/ __init__.py mainwindow.py controllers.py In this structure, for example modules contained in each package may want to access the helpers utilities through relative imports in something like: # network/clientlib.py from ..helpers.path impor

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 mod

Re: relative imports with the __import__ function

2009-12-09 Thread Chris Colbert
eter: > > def import_segmentation(name): >    return getattr(__import__("segmentation." + name, level=2, > globals=globals()), name) > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > Many thanks Peter! Almost like a charm! It seems the r

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

relative imports with the __import__ function

2009-12-08 Thread Chris Colbert
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 red_objects.py main.py launches an instance of

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
plicit 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 package, or fail. > > > Really? I thought you would still be able to use

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

2009-03-30 Thread Gabriel Genellina
bled by default- you'll *have* to use relative imports inside a package, or fail. Really? I thought you would still be able to use absolute imports; you just won't be able to use implied relative imports instead of explicit relative imports. You're right, I put it wrongly. To make

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

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. >

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

2009-03-25 Thread Gabriel Genellina
ant? I don't understand, how is this supposed to help relative imports? That's only because you have not had to deal with the problem that it solves. But I had to deal with the problem that it *creates*, even before relative imports existed, and it's a lot worse. Bindly inserting

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 > >

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

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 mod

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 fin

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

2009-03-24 Thread Istvan Albert
hs > I don't understand, how is this supposed to help relative imports? That's only because you have not had to deal with the problem that it solves. If you need to have a module that can do both: 1. access relative paths (even other packages) 2. be executable on its own (for example

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

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 brea

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
need_ to put a module file into a subpackage even when they'd only have one module file per subdirectory and they don't really know what a package is...thus bearophile's (perhaps poorly phrased) question. Now that you know what packages are and what the restrictions on relative imports ar

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

2009-03-24 Thread Maxim Khitrov
t; not contain a __init__.py file so it is not a package (i.e. not a > parent package to "Trac" and "Genshi") :0. Trac does not use relative imports to access genshi. When relative imports are not used, python goes through sys.path list to find modules (with a small excepti

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
which made no difference. I still get exactly > the same error messages. Perhaps I should have mentioned that I am > using Python 2.5, which I understand alread supports relative imports > out of the box. I'll keep this line in for now anyway though :-) > Cheers! I wrote http://

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
> |   |   __init__.py > >>     >> |   |   module2.py > > >>     >> Module1 needs to access functionality in Module2. > > >>     >> #module1.py > >>     >> from ..subpack2 import module2 > > >>     >> Seems reasonabl

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

2009-03-23 Thread Gabriel Genellina
gt; |   |   module2.py     >> Module1 needs to access functionality in Module2.     >> #module1.py     >> from ..subpack2 import module2     >> Seems reasonable to me... but it just does not work and I was so     >> liking Python. :( Another name for relative imports is &

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

2009-03-23 Thread Maxim Khitrov
I should have mentioned that I am > using Python 2.5, which I understand alread supports relative imports > out of the box. I'll keep this line in for now anyway though :-) > Cheers! Sorry, I use that line to avoid conflicts with standard modules, and forgot that relative imports ar

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

2009-03-23 Thread CinnamonDonkey
eyond toplevel package Max, thank you for the response... I tried adding "from __future__ import absolute_import" which made no difference. I still get exactly the same error messages. Perhaps I should have mentioned that I am using Python 2.5, which I understand alread supports relativ

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 c

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, 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 relativ

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
gt;  .. >  .. > > if __name__ == '__main__': >    runtests() > > But under Python 3.0 this seems impossible.  For usual use import a.py > has to become the line: > > from . import a > > But if I use that form it is no longer possible to

Re: Relative imports in Python 3.0

2008-12-17 Thread Brian Allen Vanderburg II
ain__': runtests() But under Python 3.0 this seems impossible. For usual use import a.py has to become the line: from . import a But if I use that form it is no longer possible to run b.py as a standalone script without raising an error about using relative imports. I am sure I am not the fi

Relative imports in Python 3.0

2008-12-17 Thread Nicholas
Python 3.0 this seems impossible. For usual use import a.py has to become the line: from . import a But if I use that form it is no longer possible to run b.py as a standalone script without raising an error about using relative imports. I am sure I am not the first to run into this issue, but w

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.

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

Relative imports and "import X as Y"

2008-08-30 Thread OKB (not okblacke)
I was looking at PEP 328. It says that relative imports with the dot syntax will only be allowed with the "from" import variety (e.g., "from ..somemodule import somename"). The reason given for this in the PEP is that after import xxx.yyy, "xxx.yyy" is

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
nd. > I would prefer to be able to test the file without adding anything to > the PYTHONPATH, like I said by using the name == main trick. > > So could someone explain to me what the rationale behind not allowing > parent directory relative imports is?  And possibly what I can do to > g

relative imports improve program organization... suggestions?

2008-08-08 Thread DG
en when I try the 'from __future__ import absolute_import' command. I would prefer to be able to test the file without adding anything to the PYTHONPATH, like I said by using the name == main trick. So could someone explain to me what the rationale behind not allowing parent directory rela

Importing modules from packages with relative imports

2008-05-30 Thread John Millikin
le. Is there any way to achieve the "bar.baz" name with relative imports? -- http://mail.python.org/mailman/listinfo/python-list

Fun with relative imports and py3k

2008-04-25 Thread Kay Schluehr
ot;Note that both explicit and implicit relative imports are based on the name of the current module. Since the name of the main module is always "__main__", modules intended for use as the main module of a Python application should always use absolute imports." The distinction between

Cyclic relative imports don't work

2008-04-10 Thread Torsten Bronger
moduleY File "/home/bronger/temp/packages-test/package/moduleY.py", line 1, in from . import moduleX ImportError: cannot import name moduleX If I turn the relative imports to absolute ones, it works. But I'd prefer the relative notation for intra-package imports.

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

Relative Imports

2007-07-17 Thread Pat O'Hara
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 package structure A/ __init__.

Re: Having trouble with relative imports

2007-04-10 Thread Echo
On 4/9/07, Echo <[EMAIL PROTECTED]> wrote: > Here is my setup: > rpg > -objects > --__init__.py > --gameobject.py > --material.py > -__init__.py > -run_tests.py > -stats.py > > the contents of run_test.py is: > import objects as o > > the contents of objects/__init__.py is: > from material import *

Having trouble with relative imports

2007-04-09 Thread Echo
Here is my setup: rpg -objects --__init__.py --gameobject.py --material.py -__init__.py -run_tests.py -stats.py the contents of run_test.py is: import objects as o the contents of objects/__init__.py is: from material import * in objects/material.py I have: from .gameobject import GameObject fro

Re: What is bad with "Relative imports"

2007-02-27 Thread Aahz
In article <[EMAIL PROTECTED]>, Alexander Eisenhuth <[EMAIL PROTECTED]> wrote: > >PyLint says that "Relative imports" ... are worth to be warned . > >And I ask myself why? http://www.python.org/dev/peps/pep-0328 -- Aahz ([EMAIL PROTECTED]) <*>

What is bad with "Relative imports"

2007-02-23 Thread Alexander Eisenhuth
Hi, PyLint says that "Relative imports" ... are worth to be warned . And I ask myself why? - Example directory structure - Sound/ Top-level package __init__.py Initialize the sound package

Re: help with relative imports

2006-09-19 Thread John Salerno
Robert Kern wrote: > Remember that this is code in the A.B.C module. Oh! That clears it all up! I wasn't realizing that the import statements were being executed from within the C module! Thanks! :) -- http://mail.python.org/mailman/listinfo/python-list

Re: help with relative imports

2006-09-19 Thread Robert Kern
John Salerno wrote: > Robert Kern wrote: > >> What is ambiguous about A.B.D, A.E, and A.F.G? But if you like: > > I guess maybe I was looking at it backwards. From the way it was worded, > I thought the only information we had to use was the structure A.B.C, > and then given a statement like: >

Re: help with relative imports

2006-09-19 Thread [EMAIL PROTECTED]
John Salerno wrote: > Robert Kern wrote: > > > What is ambiguous about A.B.D, A.E, and A.F.G? But if you like: > > I guess maybe I was looking at it backwards. From the way it was worded, > I thought the only information we had to use was the structure A.B.C, > and then given a statement like: > >

Re: help with relative imports

2006-09-19 Thread John Salerno
Robert Kern wrote: > What is ambiguous about A.B.D, A.E, and A.F.G? But if you like: I guess maybe I was looking at it backwards. From the way it was worded, I thought the only information we had to use was the structure A.B.C, and then given a statement like: from . import D we just had to f

Re: help with relative imports

2006-09-19 Thread Robert Kern
John Salerno wrote: > I'm reading the "What's New" section of the 2.5 docs, and I'm a little > confused by the last section of "Absolute and Relative Imports": > > --- > For example, cod

help with relative imports

2006-09-19 Thread John Salerno
I'm reading the "What's New" section of the 2.5 docs, and I'm a little confused by the last section of "Absolute and Relative Imports": --- For example, code in the A.B.C module can do: from . import D

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

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

Relative imports

2005-03-05 Thread Chris
Why do relative imports cause warnings in PyLint? A warning like this: ID:W0403 Relative import 'myPythonFileInTheSameFolder' When the import is like: from myPythonFileInTheSameFolder import MyClass -- http://mail.python.org/mailman/listinfo/python-list

Writing apps without using relative imports

2004-12-02 Thread Randall Smith
I've noticed the push by Guido and others to use absolute imports instead of relative imports. I've always enjoyed the ease of relative imports, but am starting to understand that "explicit is better than implicitly" as the Python philosophy goes. I'm trying to develo

  1   2   >