Tengo el siguiente script:
from record import record
class cliente(record):
nombre = ""
codigo = 0
ultimapelicula= None
habilitado = True
class pelicula (record):
nombre=""
codigo = 0
ultimocliente = 0
habilitada = True
def abrirbasedatos():
listaclientes = []
listapeliculas = []
ficheroclientes = abrirfichero ("Clientes.txt")
if ficheroclientes != None:
poblarlista(listaclientes, ficheroclientes,1)
ficheroclientes.close()
ficheropeliculas = abrirfichero ("C:\\Users\\IndyCarpl\\Desktop\\Menuppal\\pythong\\Peliculas.txt")
if ficheropeliculas != None:
poblarlista(listapeliculas, ficheropeliculas,2)
ficheropeliculas.close()
return listaclientes, listapeliculas
def abrirfichero (nombrearchivo):
try:
return open (nombrearchivo, "r")
except:
print ("\n\n No se puedo abrir el fichero", nombrearchivo)
return
def poblarlista(lista, fichero, numerolista):
for linea in fichero:
registro = linea.rstrip().split(",")
if numerolista == 1:
lista.append(cliente(nombre=registro[0], codigo = int(registro [1]), ultimapelicula = int(registro[2]), habilitado = convertirVF(registro[3])))
elif numerolista == 2:
lista.append(pelicula(nombre=registro [0], codigo = int(registro [1]), ultimocliente = int (registro [2]), habilitada = convertirVF(registro [3])))
return
def convertirVF (cadena):
if cadena == "True":
return True
elif cadena == "False":
return False
listaclientes, listapeliculas = abrirbasedatos()
print(listaclientes,listapeliculas)
Al ejecutarlo obtengo el siguiente error:
Traceback (most recent call last):
File "club.py", line 49, in <module>
listaclientes, listapeliculas = abrirbasedatos()
File "club.py", line 19, in abrirbasedatos
poblarlista(listaclientes, ficheroclientes,1)
File "club.py", line 39, in poblarlista
lista.append(cliente(nombre=registro[0], codigo = int(registro [1]), ultimapelicula = int(registro[2]), habilitado = convertirVF(registro[3])))
TypeError: object() takes no parameters
Edición:
Agrego mi script record.py
:
import warnings
class metaMetaBunch(type):
def __new__(cls, classname, bases, classdict):
def __init__(self, **kw):
for k in self.__dflts__: setattr(self, k, self.__dflts__[k])
for k in kw: setattr(self, k, kw[k])
def __repr__(self):
rep = [ '%s=%r' % (k, getattr(self, k)) for k in self.__dflts__
if getattr(self, k) != self.__dflts__[k]]
return '%s(%s)' % (classname, ', '.join(rep))
# Build the newdict that we'll use as class-dict for the new class
newdict = {'__slots__':[], '__dflts__':{}, '__init__':__init__, '__repr__':__repr__}
for k in classdict:
if k.startswith('__'):
# Special methods: copy to \emph{newdict}, warn about conflicts.
if k in newdict:
warnings.warn("Can't set attr %r in bunch-class %r" % (k, classname))
else:
newdict[k] = classdict[k]
else:
# Class variables, store name in \texttt{__}\emph{slots}\texttt{__} and name and value as an item in \texttt{__}\emph{dflts}\texttt{__}.
newdict['__slots__'].append(k)
newdict['__dflts__'][k] = classdict[k]
# Finally delegate the rest of the work to \emph{type}.\texttt{__}\emph{new}\texttt{__}
return type.__new__(cls, classname, bases, newdict)
class record(object):
# For convenience: inheriting from \emph{record} can be used to get the new metaclass (same as
# defining \texttt{__}\emph{metaclass}\texttt{__} yourself).
__metaclass__ = metaMetaBunch
if __name__ == "__main__":
class Point(record):
x = 0.0
y = 0.0
color = 'gray'
q = Point()
print (q)
p = Point(x=1.2, y=3.4)
print (p)
r = Point(x=2.0, color='blue')
print (r)
print (r.x, r.y)