[Tutor] Is this the right way to create a
Ricardo Araoz
ricaraoz at gmail.com
Tue Jun 24 01:22:03 CEST 2008
Kent Johnson wrote:
> On Sun, Jun 22, 2008 at 3:50 PM, Zameer Manji <zmanji at gmail.com> wrote:
>
>> I'm quite new to OOP, so forgive me if I am missing something obvious.
>> When you say that the User class should have a UserProfile as an
>> attribute, would it look something like this?
>>
>> from lastfmapi import UserProfile
>> class User (object):
>> def __init__:
>> self.UserProfile = UserProfile('Bob')
>
> Yes, that's about right. Of course 'Bob' should be an argument passed
> to __init__()
>
>> Also what do you mean by 'accessors' for Neighbors ?
>
> class User(object):
> ...
> def getNeighbors():
> """ Returns a list of this user's neighbors """
>
> and similar for getTopArtists(), etc.
>
A couple of caveats though.
Don't forget "self", it should be :
class User (object):
def __init__(self):
self.UserProfile = UserProfile('Bob')
Passing 'Bob' to __init__ would be :
class User (object):
def __init__(self, User='Bob'):
self.UserProfile = UserProfile(User)
More information about the Tutor
mailing list