I have two the python classes. I wonder if I can do something like
file A
# file A.py
from B import B
class A(){
def Foo():
pass
}
file B
# file B.py
from A import A
class B(){
def Bar():
pass
}
I have two the python classes. I wonder if I can do something like
file A
# file A.py
from B import B
class A(){
def Foo():
pass
}
file B
# file B.py
from A import A
class B(){
def Bar():
pass
}
Yes you can, however, you might be better advised to use different names for the files and the classes they contain.
Please note that the use of {}
is not a python construct to mark scope boundaries
# file a.py
from b import B
class A()
def Foo():
pass
# file b.py
from a import A
class B()
def Bar():
pass
This type of circular import will work, but there are better ways, notably placing imports in an __init__.py
file
No, you can't. Cross reference can be achieve by local import. See below example
File A:
# file A.py
from B import B
class A():
def Foo():
pass
File B:
# file B.py
class B():
def Bar():
pass
def some_function():
from A import A
# use A here