globalrev wrote:
On 16 Maj, 14:19, Bruno Desthuilliers <bruno.
[EMAIL PROTECTED]> 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
You really should back up and go through the Python tutorial.
cust1.movies() tells Python to call the object pointed to by cust1.movies (note
the parenthesis after .movies). Since that object (in your case) is a list,
that makes no sense (which is exactly what the traceback said).
print "cust", cust1.idnbr, cust1.movies
is what you want here.
-Larry
--
http://mail.python.org/mailman/listinfo/python-list