ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
>>> class A(object): attr = 1
>>> class B(A): pass
>>> class C(A): attr = 2
>>> class D(B,C): attr = B.attr
>>> x = D( )
>>> x.attr
1
why it gets the attribute 1 of A? the attribute of B is "pass",and why it goes up to get the attribute 1 of A? it did not say "attr = A.attr"? i am so confused about change from new-style class to classic class!
it is actually a new-style class,it should goes with attribute order by the new-style. why it changes the selection order of an attribute to get the attribute of A by just add "attr = B.attr"?why A? why it goes up to get A? thanks!
Last edited by topheraholic; 11-13-2009 at 09:46 PM.
If you or paulsm4 are actually curious about that, the "find more posts by" link, from the pull down from the OP's name, tends to answer such questions.
topheraholic has been asking Python and shell programming questions. You don't need to know much Python nor shell to guess this question is Python, not shell. (I'm not certain, but pretty confident, that it isn't a third language).
Topheraholic, if you actually wanted help you should have a better subject line for your thread so experts in that topic might read the thread.
If you want help with Python, put Python in the subject line. You can edit the subject line even now by editing your first post in the thread and then clicking the "go advanced" button.
It also wouldn't hurt to give a bit more background info as Pausm4 and XavierP suggested.
If you or paulsm4 are actually curious about that, the "find more posts by" link, from the pull down from the OP's name, tends to answer such questions.
topheraholic has been asking Python and shell programming questions. You don't need to know much Python nor shell to guess this question is Python, not shell. (I'm not certain, but pretty confident, that it isn't a third language).
Good find. Though I would question the need for anyone to have to search a user's history to find out what help they actually need. If anyone comes to someone for help, a basic is to give them the tools/info to do so.
That said, a code snippet (I assume that this is what we're getting) is of limited use, if we know what it should be doing, what it actually is doing and what has been done to it we can then bring out an answer.
Sorry about side tracking the thread even further, but...
Quote:
Originally Posted by XavierP
I would question the need for anyone to have to search a user's history to find out what help they actually need.
It's more about some combination of curiosity and helpfulness, certainly not "need .. to search". But I routinely check the OP's other recent posts for insight into various aspects of the question.
People should not ask follow up questions in a new thread, providing neither a link to the previous thread nor background info in the new question. But in fact they do so. There is context in a previous thread often enough that is is worth checking.
People also frequently quote out of context fragments of information from some online source without providing a link nor even mentioning that they are quoting a fragment from an online source. When I guess that has happened (more often in IR forums than at LQ, but sometimes here as well) I google the quote and usually find the same online source, so I then know what they misunderstood as the basis for their question.
Yeah, admittedly I was thinking more in an "ideal world" scenario rather than an "actual world". Internet detectivery should only be applied for fun and/or malice () not to be able to provide help!
It looks like you had a "WTF moment" when you read my reply. Exactly the point I was trying to make: if you ask a question, you need to put the question in some kind of "context". In this case, we needed to know a) you were asking about Python, b) you were in the Python interpreter, and c) your question was about how Python treats an attribute that's defined in one class appears in different class (one that "uses" the first class).
% # Here's another, slightly different example:
% python
Python 2.4 (#1, Mar 22 2005, 21:42:42)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> # Define some class "A" and use it:
... class A(object) : attr = 1
...
>>> a = A()
>>> a.attr
1
>>> # Now define class "B":
... class B(object) : attr = 2
...
>>> b = B()
>>> b.attr
2
>>> # Finally, what happens if class "C" is composed of "A" and "B"?
... class C(B,A) : pass
...
>>> c = C()
>>> c.attr
2
'Hope that helps .. PSM
PS:
To paraphrase The Beatles (from "Sgt. Pepper"): always please "indicate precisely what you mean to say..."
It looks like you had a "WTF moment" when you read my reply. Exactly the point I was trying to make: if you ask a question, you need to put the question in some kind of "context". In this case, we needed to know a) you were asking about Python, b) you were in the Python interpreter, and c) your question was about how Python treats an attribute that's defined in one class appears in different class (one that "uses" the first class).
% # Here's another, slightly different example:
% python
Python 2.4 (#1, Mar 22 2005, 21:42:42)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> # Define some class "A" and use it:
... class A(object) : attr = 1
...
>>> a = A()
>>> a.attr
1
>>> # Now define class "B":
... class B(object) : attr = 2
...
>>> b = B()
>>> b.attr
2
>>> # Finally, what happens if class "C" is composed of "A" and "B"?
... class C(B,A) : pass
...
>>> c = C()
>>> c.attr
2
'Hope that helps .. PSM
PS:
To paraphrase The Beatles (from "Sgt. Pepper"): always please "indicate precisely what you mean to say..."
thanks for the suggestions of all your guy!
i know what you have pointed out,but maybe my point is not that simple.
Code:
>>> class A(object): attr = 1
>>> class B(A): pass
>>> class C(A): attr = 2
>>> class D(B,C): attr = B.attr
>>> x = D( )
>>> x.attr
1
this is a new-style class,what is confusing me is why it change the search order of an attribute just by add "attr = B.attr"? why it goes up to class A? the original new-style class search order of an attribute is D B C and then A.and now it is D B A , right? why A? the expression "attr = B.attr" is just a sign of changing search order of classic class to new-style, what is the search order if A is the place where classes are mixed together A(A1,A2)? it goes like this"D B A A1 C A2" or "D B A C A1 A2" the "attr = B.attr" is a one-time job or change the entire search order from new-style class to classic class? thanks!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.