How would I create an class with a "Person.Address.City" property?

Jamie J. Begin jjbegin at rightbrainnetworks.com
Tue Dec 19 02:04:40 EST 2006


I'm very new to the world of Python and am trying to wrap my head around
it's OOP model. Much of my OOP experience comes from VB.Net, which is
very different.

Let's say I wanted to create an object that simply outputted something
like this:

>>> import employees
>>> person = employee("joe") # Get Joe's employment file
>>> print employee.Title # What does Joe do?
Developer
>>> print person.Address.City # Which city does Joe live in?
Detroit
>>> print person.Address.State # Which state?
Michigan

To do this would I create nested "Address" class within the "employee"
class? Would it make more sense to just use "print
person.Address('City')" instead?

Thanks for your help!



More information about the Python-list mailing list