If I run the file that has this code, I have no problems and everything is smooth. I'm now calling this class in another file and for some reason I get this error:
Traceback (most recent call last):
File "C:\users\cato\work\reports\runReports.py", line 524, in runAllAdmis
self.sortAcctCol()
File "C:\users\cato\work\reports\runReports.py", line 553, in sortAcctCol
with open(self.inFile, "r") as self.oi, self.temp1:
AttributeError: __exit__
I don't understand why it's working in the original file and not when I call it from another. I looked up my error message and I found this question but when I tried configuring my code to match, I couldn't figure out how to apply it in my situation. I think this mostly due to me not understanding the actual error.
This is my code:
def sortAcctCol(self):
with open(self.inFile, "r") as self.oi, self.temp1:
r = csv.reader(self.oi)
w = csv.writer(self.temp1)
self.header = next(r)
self.sortedCol = sorted(r, key=operator.itemgetter(self.acct), reverse=False)
for row in self.sortedCol:
w.writerow(row)
self.temp1 = self.temp1.name