1

I have the following structure:

class foo(object):
  class bar(object):
    def __init__(self, parent):
      self._parent=parent             #this

    def worker(self):
      return self._parent.name

  def __init__(self, name):
    self.name=name

  def giveNamePointer(self):
    return self.bar(self)             #and this

Which works fine, however I was wondering if there is an implicit or easier way to get the reference to the creating instance in the special case, that the created instance is a class defined in the creating class.

edit: could this help me :implementing descriptiors and if so how?

1 Answer 1

1

No. Explicit is better than implicit.

(There's nothing special about defining a class inside another class.)

Sign up to request clarification or add additional context in comments.

2 Comments

well the surrounding scope changes, but i will accept pythons zen

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.