class problem, NoneType obj has no attribute
globalrev
skanemupp at yahoo.se
Fri May 16 09:11:55 EDT 2008
On 16 Maj, 14:19, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:
> globalrev a écrit :
>
> > wassup here?
>
> > 7
>
> > Traceback (most recent call last):
> > File "C:\Python25\myPrograms\netflix\netflix.py", line 22, in
> > <module>
> > print cust1.getID()
> > AttributeError: 'NoneType' object has no attribute 'getID'
>
> > class customer:
>
> 1/ naming convention : class names should be CamelCased
> 2/ unless you need compatibility with years old Python versions, use
> newstyle classes
>
> class Customer(object):
>
> > def __init__(self, ID, movies):
> > self.ID = ID
> > self.movies = movies
>
> 3/ naming conventions : ALL_UPPER_NAMES denote (pseudo) constants
>
> def __init__(self, id, movies):
> self.id = id
> self.movies = movies
>
> > def getID():
> > return self.ID
>
> > def getMovies():
> > return self.movies
>
> 4/ Python has support for computed attributes, so you just don't need
> these getters.
>
>
>
> > import os
> > import customer
> > import movie
>
> > mv1 = open('C:\\Python25\\myPrograms\\netflix\\mv1exp2.txt', 'r+')
> > mv1str = mv1.read()
>
> > print mv1str.count(',5,')
>
> > cust1 = customer.__init__('12',['1','435','2332'])
>
> __init__ is automagically called on instanciation, so you don't have to
> call it yourself. And FWIW, your __init__ returns None.
>
> cust1 = Customer('12', ['1', '435', '2332'])
>
> > print cust1.getID()
>
> print cust1.id
print "cust", cust1.idnbr, cust1.movies()
Traceback (most recent call last):
File "C:\Python25\myPrograms\netflix\netflix.py", line 24, in
<module>
print "cust", cust1.idnbr, cust1.movies()
TypeError: 'list' object is not callable
when class =
class customer:
def __init__(self, idnbr, movies):
self.idnbr = idnbr
self.movies = movies
print "cust", cust1.idnbr, cust1.movies()
Traceback (most recent call last):
File "C:\Python25\myPrograms\netflix\netflix.py", line 24, in
<module>
print "cust", cust1.idnbr, cust1.movies()
TypeError: 'list' object is not callable
when class =
class customer:
def __init__(self, idnbr, movies):
self.idnbr = idnbr
self.movies = movies
More information about the Python-list
mailing list