person = Person():
  name = "john"
  age = 30
  address = Address():
     street = "Green Street"
     no = 12


Can you clarify what you mean? Would that define a Person class, and an Address class?

If you are expecting those classes to be already defined, please bear in mind that if you want, you can do this:

> > class Person(object):
        def __init__(self, name='Nemo', age=0, address=None):
                self.name = name
                self.age = age
                self.address = address

> > class Address(object):
        def __init__(self, street=None, no=None):
                self.street = street
                self.no = no
        
> > otherperson = Person(
                     name = 'Bob',
                     age = 26,
                     address = Address(
                             street = 'Blue Street',
                             no = 1
                             )
                     )







On Wed, 26 Aug 2009 09:49:48 -0700, zaur <szp...@gmail.com> wrote:

On 26 авг, 17:13, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
Whom am we to judge? Sure if you propose this, you have some usecases in
mind - how about you present these

Ok. Here is a use case: object initialization.

For example,

person = Person():
  name = "john"
  age = 30
  address = Address():
     street = "Green Street"
     no = 12

vs.

person = Person()
person.name = "john"
person.age = 30
address = person.address = Address()
address.street = "Green Street"
address.no = 12

In this example any assignment is an equivalence of setting
attribute's address of the parent object.



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to