3

We just started learning about class inheritance and attribute lookup in python. I have a question about the following code:

class a : n = 1
class b : n = 2
class c : n = 3
class d (a,b) : pass
class e (d,c) : pass

I know that e.n would equal 1 due to the nature of attribute lookup procedure (depth first search). However, how would I access, say, class c's n from class e? I've tried e.c.n, but that gives me an error. Can someone tell me what I'm doing wrong? Thanks in advance!

Geoff Reedy
36.4k3 gold badges60 silver badges79 bronze badges
asked Feb 17, 2010 at 7:23

2 Answers 2

1
>>> e.__bases__[1].n
3
answered Feb 17, 2010 at 7:57
Sign up to request clarification or add additional context in comments.

Comments

1

You can't get there from here. Class attributes are replaced. Use the class reference directly (c.n).

answered Feb 17, 2010 at 7:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.