2

In Python, if I have something like:

class A(object):
    b = B()


class B(object):
   a = A()

Will produce an error NameError: name 'B' is not defined

How would you elegantly resolve this ?

1 Answer 1

3

Try:

class B(object):
    pass

class A(object):
    b = B()

B.a = A()
Sign up to request clarification or add additional context in comments.

2 Comments

if B has another static member, it cannot be accessed from A.b.another_stativ_var . I would have liked to have the other static members defined inside the class.
@Martijn Pieters Yes you can. My mistake. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.