Custom Search

Sunday, December 19, 2010

Python Django Types and Objects

Python Django Types and Objects

print "\n* object ------> class 'object' "
print "\n* object() -----> creating object of class 'object' "
print "\n-----------object------------", object
print "\n-----------object()------------", object()
print "\n-----------type(object)------------", type(object)
print "\n-----------type(object())------------", type(object())
print "\n-----------object.__class__------------", object.__class__
print "\n-----------object().__class__------------", object().__class__
print "\n-----------object.__bases__------------", object.__bases__
#print "\n-----------object().__bases__---------AttributeError: 'object'
object has no attribute '__bases__'---", object().__bases__


print "\n**************************************************"


print "\n-----------type------------", type
print "\n-----------type(type)------------", type(type)
print "\n-----------type(type(type))------------", type(type(type))
print "\n-----------type.__class__------------", type.__class__
print "\n-----------type(type).__class__------------", type(type).__class__
print "\n-----------type.__bases__------------", type.__bases__


print "\n**************************************************"

print "\n-----------list------------", list
print "\n-----------list()------------", list()
print "\n-----------type(list)------------", type(list)
print "\n-----------type(list())------------", type(list())
print "\n-----------list.__class__------------", list.__class__
print "\n-----------list().__class__------------", list().__class__
print "\n-----------list.__bases__------------", list.__bases__


print "\n**************************************************"


print "\n-----------dict------------", dict
print "\n-----------dict()------------", dict()
print "\n-----------type(dict)------------", type(dict)
print "\n-----------type(dict())------------", type(dict())
print "\n-----------dict.__class__------------", dict.__class__
print "\n-----------dict().__class__------------", dict().__class__
print "\n-----------dict.__bases__------------", dict.__bases__


print "\n**************************************************"


print "\n-----------tuple------------", tuple
print "\n-----------tuple()------------", tuple()
print "\n-----------type(tuple)------------", type(tuple)
print "\n-----------type(tuple())------------", type(tuple())
print "\n-----------tuple.__class__------------", tuple.__class__
print "\n-----------tuple().__class__------------", tuple().__class__
print "\n-----------tuple.__bases__------------", tuple.__bases__


print "\n**************************************************"


print "\n-----------str------------", str
print "\n-----------str()------------", str()
print "\n-----------type(str)------------", type(str)
print "\n-----------type(str())------------", type(str())
print "\n-----------str.__class__------------", str.__class__
print "\n-----------str().__class__------------", str().__class__
print "\n-----------str.__bases__------------", str.__bases__
print "\n-----------basestring.__bases__------------", basestring.__bases__


print "\n**************************************************"


print "\n-----------int------------", int
print "\n-----------int()------------", int()
print "\n-----------type(int)------------", type(int)
print "\n-----------type(int())------------", type(int())
print "\n-----------int.__class__------------", int.__class__
print "\n-----------int().__class__------------", int().__class__
print "\n-----------int.__bases__------------", int.__bases__


print "\n**************************************************"


print "\n* ====Python Built-In Classes====== object, type, list, dict, type, str, int,
float, etc---"
print "\n* ====object of Python Built-In Classes====== object(), type(), list(), dict(),
type(), str(), int(), float(), etc---"


print "\n**************************************************"


print"\n======= creating object of Built-In Classes=========="
print "\n--------[] and list() are same---------------", [], list()
print "\n--------{} and dict() are same---------------", {}, dict()
print "\n--------() and tuple() are same---------------", (), tuple()
print "\n--------'' and str() are same---------------", '', str()
print "\n--------0 and int() are same---------------", 0, int()
print "\n--------0.0 and float() are same---------------", 0.0, float()


print "\n**************************************************"


print"\n======= 'object' is the base or super class of all Built-In Classes=========="
print "\n----No Base class for class 'object'---------object.__bases__------------",
object.__bases__
print "\n-----------type.__bases__------------", type.__bases__
print "\n-----------list.__bases__------------", list.__bases__
print "\n-----------dict.__bases__------------", dict.__bases__
print "\n-----------tuple.__bases__------------", tuple.__bases__
print "\n-----------str.__bases__------------", str.__bases__
print "\n-----------basestring.__bases__------------", basestring.__bases__
print "\n-----------int.__bases__------------", int.__bases__
print "\n-----------float.__bases__------------", float.__bases__


print "\n**************************************************"


print"\n======= type of Built-In Classes are 'type' =========="
print "\n-----------type(object)------------", type(object)
print "\n-----------type(type)------------", type(type)
print "\n-----------type(list)------------", type(list)
print "\n-----------type(dict)------------", type(dict)
print "\n-----------type(tuple)------------", type(tuple)
print "\n-----------type(str)------------", type(str)
print "\n-----------type(int)------------", type(int)
print "\n-----------type(float)------------", type(float)


print "\n**************************************************"


print"\n======= type of Built-In Class object =========="
print "\n-----------type(object())------------", type(object())
print "\n-----------type(type())------------", type(type(type))
print "\n-----------type(list())------------", type(list())
print "\n-----------type(dict())------------", type(dict())
print "\n-----------type(tuple())------------", type(tuple())
print "\n-----------type(str())------------", type(str())
print "\n-----------type(int())------------", type(int())
print "\n-----------type(float())------------", type(float())




OUTPUT
==========


# python aa.py

* object ------> class 'object'

* object() -----> creating object of class 'object'

-----------object------------ type 'object'>

-----------object()------------ object object at 0x7f1502ad0090>

-----------type(object)------------ type 'type'>

-----------type(object())------------ type 'object'>

-----------object.__class__------------ type 'type'>

-----------object().__class__------------ type 'object'>

-----------object.__bases__------------ ()

**************************************************

-----------type------------ type 'type'>

-----------type(type)------------ type 'type'>

-----------type(type(type))------------ type 'type'>

-----------type.__class__------------ type 'type'>

-----------type(type).__class__------------ type 'type'>

-----------type.__bases__------------ (type 'object'>,)

**************************************************

-----------list------------ type 'list'>

-----------list()------------ []

-----------type(list)------------ type 'type'>

-----------type(list())------------ type 'list'>

-----------list.__class__------------ type 'type'>

-----------list().__class__------------ type 'list'>

-----------list.__bases__------------ (type 'object'>,)

**************************************************

-----------dict------------ type 'dict'>

-----------dict()------------ {}

-----------type(dict)------------ type 'type'>

-----------type(dict())------------ type 'dict'>

-----------dict.__class__------------ type 'type'>

-----------dict().__class__------------ type 'dict'>

-----------dict.__bases__------------ (type 'object'>,)

**************************************************

-----------tuple------------ type 'tuple'>

-----------tuple()------------ ()

-----------type(tuple)------------ type 'type'>

-----------type(tuple())------------ type 'tuple'>

-----------tuple.__class__------------ type 'type'>

-----------tuple().__class__------------ type 'tuple'>

-----------tuple.__bases__------------ (type 'object'>,)

**************************************************

-----------str------------ type 'str'>

-----------str()------------

-----------type(str)------------ type 'type'>

-----------type(str())------------ type 'str'>

-----------str.__class__------------ type 'type'>

-----------str().__class__------------ type 'str'>

-----------str.__bases__------------ (type 'basestring'>,)

-----------basestring.__bases__------------ (type 'object'>,)

**************************************************

-----------int------------ type 'int'>

-----------int()------------ 0

-----------type(int)------------ type 'type'>

-----------type(int())------------ type 'int'>

-----------int.__class__------------ type 'type'>

-----------int().__class__------------ type 'int'>

-----------int.__bases__------------ (type 'object'>,)

**************************************************

* ====Python Built-In Classes====== object, type, list, dict, type, str, int, float, etc---

* ====object of Python Built-In Classes====== object(), type(), list(), dict(), type(),
str(), int(), float(), etc---

**************************************************

======= creating object of Built-In Classes==========

--------[] and list() are same--------------- [] []

--------{} and dict() are same--------------- {} {}

--------() and tuple() are same--------------- () ()

--------'' and str() are same---------------

--------0 and int() are same--------------- 0 0

--------0.0 and float() are same--------------- 0.0 0.0

**************************************************

======= 'object' is the base or super class of all Built-In Classes==========

----No Base class for class 'object'---------object.__bases__------------ ()

-----------type.__bases__------------ (type 'object'>,)

-----------list.__bases__------------ (type 'object'>,)

-----------dict.__bases__------------ (type 'object'>,)

-----------tuple.__bases__------------ (type 'object'>,)

-----------str.__bases__------------ (type 'basestring'>,)

-----------basestring.__bases__------------ (type 'object'>,)

-----------int.__bases__------------ (type 'object'>,)

-----------float.__bases__------------ (type 'object'>,)

**************************************************

======= type of Built-In Classes are 'type' ==========

-----------type(object)------------ type 'type'>

-----------type(type)------------ type 'type'>

-----------type(list)------------ type 'type'>

-----------type(dict)------------ type 'type'>

-----------type(tuple)------------ type 'type'>

-----------type(str)------------ type 'type'>

-----------type(int)------------ type 'type'>

-----------type(float)------------ type 'type'>

**************************************************

======= type of Built-In Class object ==========

-----------type(object())------------ type 'object'>

-----------type(type())------------ type 'type'>

-----------type(list())------------ type 'list'>

-----------type(dict())------------ type 'dict'>

-----------type(tuple())------------ type 'tuple'>

-----------type(str())------------ type 'str'>

-----------type(int())------------ type 'int'>

-----------type(float())------------ type 'float'>



Read More....

No comments:

Post a Comment