473,394 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Import Error ('mutual inclusion of modules'?)

I have the following code:

A.py
====

from B import B

class R:
def __str__(self):
return "hello world"

b = B()
print b
B.py
====

from A import R
class B:

def __init__(self):
self.r = R()

def __str__(self):
return self.r.__str__()

When I try to execute A.py I get the following error:

[python2.3]$ python A.py
Traceback (most recent call last):
File "A.py", line 1, in ?
from B import B
File "python2.3/B.py", line 1, in ?
from A import R
File "python2.3/A.py", line 1, in ?
from B import B
ImportError: cannot import name B
I think python does not support this kind of 'mutual inclusion'. Am I
right? Thanks. Cesar.

Aug 23 '05 #1
2 2724
<ic***@yahoo.com> wrote:
I have the following code:

A.py
====

from B import B B.py
====

from A import R I think python does not support this kind of 'mutual inclusion'. Am I
right? Thanks. Cesar.


this page

http://effbot.org/zone/import-confusion.htm

might help you figure out what's going on here.

</F>

Aug 23 '05 #2
Thanks,
I had not found anything about it. But I had not search correctly.
There is an entry in the FAQ about it:

http://www.python.org/doc/faq/progra...ort-each-other

I like the most the third way.
I have also tried to move the import to the __init__ methos in B.py and
it works.

Aug 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Markus Doering | last post by:
Hello, I just switched from 2.2 to Python 2.3. I am developing an XML/CGI interface to databases as a python package called "unitWrapper" containing several modules which ran fine under v2.2. ...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
4
by: MackS | last post by:
Hi I'm new to Python, I've read the FAQ but still can't get the following simple example working: # file main_mod.py: global_string = 'abc' def main():
9
by: ajikoe | last post by:
Hello, I have two modules (file1.py and file2.py) Is that ok in python (without any weird implication) if my module import each other. I mean in module file1.py there exist command import file2...
1
by: mirandacascade | last post by:
O/S: Windows 2K Vsn of Python: 2.4 Currently: 1) Folder structure: \workarea\ <- ElementTree files reside here \xml\ \dom\
3
by: kwatch | last post by:
What is the condition of module name which is available in 'from .. import ..' statement ? ---------------------------------------- import os print os.path # <module 'posixpath'...
0
by: Laxmikumar | last post by:
Iam new to web services, Iam using net beans-5.5.1 IDE whlie deploying the web service application the following error is occured. can anyone help me..??? please. init: deps-module-jar:...
10
by: Thomas Guettler | last post by:
If you look at this code, you see there are two kind of ImportErrors: 1. app_name has no attribute or file managment.py: That's OK. 2. managment.py exists, but raises an ImportError: That's not...
4
by: jimgardener | last post by:
I am new to python,and am learning from the tutorials i created 2 .py files like below and put the main in one of them empmodule.py ---------- from workmodule import Worker class Employer:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.