Ich bin neu in Klassen und ich bin diesen Fehler:Error 'NoneType' Objekt hat kein Attribut 'lesen'
self.a2=self.f2.read()
AttributeError: 'NoneType' object has no attribute 'read'
dies ist mein Code:
class flights(object):
"""
A class that can read in files about flights and report that information
"""
def __init__(self, filename1,filename2):
"""when typing in the filename1 and filename2 make
sure to put them is as "filename.txt"
"""
self.filename1=filename1
self.filename2=filename2
self.f1=None# none is a place holder
self.f2=None
self.a1=None
def showx(self):
print(self.filename1)
print(self.filename2)
def readfile(self):
self.f1=open(self.filename1,'r')
self.a1=self.f1.read()
self.f1=open(self.filename2,'r')
self.a2=self.f2.read()
print(self.a1)
print(self.a2)
weiß jemand, Warum funktioniert das nicht?
Es zeigt Ihnen sehr deutlich in der Ausnahme, dass 'f2' auf' None' gesetzt ist. Ihr Fehler ist wahrscheinlich in der 3. Zeile in "Readfile" – Shadow
die Person unter respektvoll beantwortet. – Brit