LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-07-2009, 08:38 AM   #1
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Rep: Reputation: 15
python, please,what is the difference between one.__class__ and one().__class__?


the script is this:

Code:
class one:
   pass
class two(one):
   pass
i got an error when i ran

Code:
two.__class__
who can tell me why?
what is the difference between
Code:
object.__class__ and object().__class__
thanks very much!
 
Old 11-08-2009, 05:49 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by topheraholic View Post
what is the difference between
Code:
object.__class__ and object().__class__
thanks very much!
object is a class.
object() is an instance of the class 'object'.

object.__class__ is referring to the class of the object class.
object().__class__ is referring to the class of an instance of the 'object' class.

So, object().__class__.__class__ is the same as object.__class__

Quote:
Originally Posted by topheraholic View Post
i got an error when i ran
Code:
two.__class__
who can tell me why?
two is a class. So you might expect two.__class__ to be: <type 'classobj'>.

But then two.__class__.__class__ would be: <type 'classobj'> too.

And two.__class__.__class__.__class__.__class__.__class__ too. This never ends. That is why, I suppose, <class>.__class__ is not defined.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script to find the difference betwwn two file and place the difference to other kittunot4u Linux - General 3 07-19-2010 04:26 AM
install p4vasp, what is the difference between python-gtk and pygtk ? centguy Linux - Software 5 10-29-2009 01:07 PM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
LXer: Review: Programming in Python 3: A Complete Introduction to the Python Language LXer Syndicated Linux News 0 01-26-2009 04:50 AM
LXer: Move to python 2.4 / Changing the packaging style for python packages LXer Syndicated Linux News 0 06-13-2006 07:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration