On 26 авг, 23:56, MRAB <pyt...@mrabarnett.plus.com> wrote:
> zaur wrote:
> > On 26 авг, 21:11, "Rami Chowdhury" <rami.chowdh...@gmail.com> wrote:
> >>> 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?
> > I suppose that someone already define classes Person ans Address.
> > For example, in this stupid way in a foreign module:
>
> > class Person(object):
> >    pass
>
> > class Address(object):
> >    pass
>
> > and the following statements
>
> > person = Person():
> >    name = "john"
> >    age = 30
> >    address = Address():
> >       street = "Green Street"
> >       no = 12
>
> > are constructing an instance as follows:
>
> > person = Person()
> > person.name = "john"
> > person.age = 30
> > address = person.address = Address()
> > address.street = "Green Street"
> > address.no = 12
>
> [snip]
>
> Create factory functions:
>
> def new_address(**kwargs):
>      address = Address()
>      address.__dict__.update(kwargs)
>      return address
>
> def new_person(**kwargs):
>      person = Person()
>      person.__dict__.update(kwargs)
>      return person
>
> person = new_person(name="john", age=30,
> address=new_address(street="Green Street", no=12))

Original idea isn't about how to organize my code in order to
initialize these custom objects.
The idea is about to use object's dictionary as nested scope.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to