Need help with OOP
Jay O'Connor
joconnor at cybermesa.com
Fri Nov 7 01:01:45 EST 2003
More information about the Python-list mailing list
Fri Nov 7 01:01:45 EST 2003
- Previous message (by thread): Need help with OOP
- Next message (by thread): Need help with OOP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 7 Nov 2003 05:36:57 +0100, sinisam <X.3.M__antispam__ at mail.ru> wrote: >Next part (even though I said I know *nothing* about OOP) is: > >"Make class for the IP address. It should be initialized from the >string. Later on, we can add functions to it." > >[1] What in the world I have to do here? >[1a] How to make class for the IP address? What does it mean? One feature you will often see in OOP is the idea of 'wrapping' more primitive concepts into objects and then giving those objects more functionality as a means of convenience. For example, while it is possible to trate a phone number as a simple string such as phoneNumber = '102.555.1234' You can also wrapper the simple string in a class and then give it extra functionality phoneNumber = PhoneNumber() phoneNumber._number = "102.555.1234" pre = phoneNumber.prefix() the function "prefix()" is defined by the PhoneNumber class as an easier way of dealing with the phone number. To create this wrapper class in Python is easy class PhoneNumber: def __init__(self): self._number = '' def prefix (self): return self._number[4:7] So the question being asked is to write a similar wrapper class that will do the same for IP addresses >[2] "Initialization from the string" means something like passing >arguments from the command line...? No, it means that when you create the object, you will provide some information that will set the default state of the new object person = Person ("O'Connor", "James") this is done by providing paramaters for your initialization function for the class class Person: def __init__(self, lastName, firstName): self._lastName = lastName self._firstName = firstName This sets the lastName and firstName of the person to whatever you tell it to be when you create the object >Of course, I don't expect you to do the job for me, but I would sure >appreciate help. I know this is easy, but as stated before, I don't >know how to handle objects... yet :) The above explanation and examples are sparse, but should be sufficient to move you in the right direction to solve your problem Take care, Jay
- Previous message (by thread): Need help with OOP
- Next message (by thread): Need help with OOP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list