Hi,
why does Python only raise ImportError if it fails caused by a recursive import?
I know what's wrong. But I guess many beginner don't know what's wrong. I don't
want much, just "RecursiveImportError" instead of "ImportError". Is this possible?
Thomas
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de 4 1599
On Thu, 11 Sep 2008 12:43:34 +0200, Thomas Guettler wrote:
why does Python only raise ImportError if it fails caused by a recursive
import?
I know what's wrong. But I guess many beginner don't know what's wrong.
I don't want much, just "RecursiveImportError" instead of "ImportError".
Is this possible?
Can you give an example of such a recursive import you want the special
exception be raised?
Ciao,
Marc 'BlackJack' Rintsch
Hi,
Can you give an example of such a recursive import you want the special
exception be raised?
===cat one.py
from two import testtwo
def testone():
print "one"
===cat two.py
import one
def testtwo():
print "two"
===python one.py
Traceback (most recent call last):
File "one.py", line 1, in <module>
from two import testtwo
File "/mnt/home/tguettler/tmp/rec/two.py", line 1, in <module>
import one
File "/mnt/home/tguettler/tmp/rec/one.py", line 1, in <module>
from two import testtwo
ImportError: cannot import name testtwo
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
On Fri, 12 Sep 2008 09:47:42 +0200, Thomas Guettler wrote:
>Can you give an example of such a recursive import you want the special exception be raised?
===cat one.py
from two import testtwo
def testone():
print "one"
===cat two.py
import one
def testtwo():
print "two"
===python one.py
Traceback (most recent call last):
File "one.py", line 1, in <module>
from two import testtwo
File "/mnt/home/tguettler/tmp/rec/two.py", line 1, in <module>
import one
File "/mnt/home/tguettler/tmp/rec/one.py", line 1, in <module>
from two import testtwo
ImportError: cannot import name testtwo
This is an awkward situation anyway because here are *three* modules
involved. You start `one.py` which will be imported as `__main__`.
`__main__` imports `two` and `two` imports a *new* module `one`! Which
tries to import `testtwo` from `two` which doesn't exist at that time.
Even if you rearrange the code to load properly `one.py` is loaded and
executed *twice* and you end up with two distinct modules generated from
that file.
Ciao,
Marc 'BlackJack' Rintsch
On Thu, 11 Sep 2008 12:43:34 +0200, Thomas Guettler wrote:
Hello,
why does Python only raise ImportError if it fails caused by a recursive import?
I know what's wrong. But I guess many beginner don't know what's wrong.
I don't think that you're right here. I can't remember any beginner
asking such a question on p.c.py. I think they would come and ask
if it really was problematic.
And, anyway, I don't know how to answer your question :-)
--
Regards,
Wojtek Walczak, http://tosh.pl/gminick/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stian Søiland |
last post by:
all examples performed with:
Python 2.3+ (#2, Aug 10 2003, 11:09:33)
on linux2
(2, 3, 0, 'final', 1)
This is a recursive import:
|
by: Maurice LING |
last post by:
Hi,
I have the following codes:
from __future__ import nested_scopes
import re
from UserDict import UserDict
class Replacer(UserDict):
|
by: aurora |
last post by:
I love generator and I use it a lot. Lately I've been writing some
recursive generator to traverse tree structures. After taking closer look
I have some concern on its performance.
Let's take...
|
by: erik.erikson |
last post by:
I am getting a compiler error that I can't well explain or even
understand the origin of (though I boiled it down close...). Below is
a bare-bones example.
What I am doing is defining the...
|
by: sebastien.abeille |
last post by:
Hello,
I would like to create a minimalist file browser using pyGTK.
Having read lot of tutorials, it seems to me that that in my case, the
best solution is
to have a gtk.TreeStore containing...
|
by: Martin Marcher |
last post by:
Hello,
I'm playing around with os.walk and I made up del_tree(path) which I
think is correct (in terms of the algorithm, but not as python wants
it :)).
As soon as some directory is deleted...
|
by: Just Another Victim of the Ambient Morality |
last post by:
Is pyparsing really a recursive descent parser? I ask this because
there are grammars it can't parse that my recursive descent parser would
parse, should I have written one. For instance:
...
|
by: pereges |
last post by:
How to to go about this ? Suppose a malloc inside a recursive function
has failed and you want to set the error flag and return it to the
calling function(the one which called the recursive...
|
by: from.future.import |
last post by:
Hi,
I encountered garbage collection behaviour that I didn't expect when
using a recursive function inside another function: the definition of
the inner function seems to contain a circular...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |