Python Error self.reader.next() -
i receiving error , don't know how fix it. error show below along program. beginner programming new me. program's goal read information based of year , location , print out corresponding information psse
traceback (most recent call last): file "c:/users/roszkowskim/desktop/dictreader.py", line 75, in <module> row in reader: file "c:\python27\lib\csv.py", line 103, in next self.fieldnames file "c:\python27\lib\csv.py", line 90, in fieldnames self._fieldnames = self.reader.next() valueerror: i/o operation on closed file
_
import csv load_gen_datafile = 'c:\users\roszkowskim\desktop\data_2017.csv' open(load_gen_datafile) csvfile: reader = csv.dictreader(csvfile) mydict = {} row in reader: year=row['year'] busnum=row['busnum'] area=row['area'] power=row['power'] tla=row['tla'] location=row['location'] yearlink=row['yearlink'] from=row['from'] to=row['to'] max=row['max'] min=row['min'] year = raw_input("please select year of study: ") print("\n") commands = ["millwood-buchanan", "astoria-east-corona", "bronx", "dunwoodie-north-sherman_creek", "vernon", "greenwood-statenisland","west_49th","east_13th","staten_island","east_river", "east_view","dunwoodie-south","corona-jamaica","astoria-east-corona-jamaica", "astoria-west-queensbridge-vernon","astoria-west-queensbridge"] max_columns = 50 index, commands in enumerate(commands): stars_amount = max(max_columns - len(commands), 0) row = "# {} {}({})".format(commands, "." * stars_amount, index + 1) print(row) location=raw_input(" \n list above show tla pockets id numbers assigned them ()\n\n please enter id #: ") print("\n") if year in year , location in location: mydict=(busnum,area,power) print("here busses @ location year , new load total: ") print("\n") #busnum, busname,scaled_power read excel sheet matching year , location busnum,area,power in mydict: power= float(scaled_power) busnum = int(busnum) print('bus #: %d\t' % busnum ,'area station: %s\t'% area,'new load total: %d mw\t' % power) #api changing , scaling generation of loads #psspy.bsys(1,0,[0.0,0.0],0,[],1,[busnum],0,[],0,[]) #psspy.scal_2(1,0,1,[0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0]) #psspy.scal_2(0,1,2,[0,1,0,1,0],[power,0.0,0,-.0,0.0,-.0,0]) #print("\n")
else: exit
when used with
file stays open long in scope, when for row in reader:
indented incorrectly file gets closed, tested below , please select year of study:
import csv load_gen_datafile = 'c:\\users\\dirty-santa\\desktop\\blah.csv' open(load_gen_datafile) csvfile: reader = csv.dictreader(csvfile) mydict = {} row in reader: year=row['year'] busnum=row['busnum'] area=row['area'] power=row['power'] tla=row['tla'] location=row['location'] yearlink=row['yearlink'] from=row['from'] to=row['to'] max=row['max'] min=row['min'] year = raw_input("please select year of study: ") print("\n") commands = ["millwood-buchanan", "astoria-east-corona", "bronx", "dunwoodie-north-sherman_creek", "vernon", "greenwood-statenisland","west_49th","east_13th","staten_island","east_river", "east_view","dunwoodie-south","corona-jamaica","astoria-east-corona-jamaica", "astoria-west-queensbridge-vernon","astoria-west-queensbridge"] max_columns = 50 index, commands in enumerate(commands): stars_amount = max(max_columns - len(commands), 0) row = "# {} {}({})".format(commands, "." * stars_amount, index + 1) print(row) location=raw_input(" \n list above show tla pockets id numbers assigned them ()\n\n please enter id #: ") print("\n") if year in year , location in location: mydict=(busnum,area,power) print("here busses @ location year , new load total: ") print("\n") #busnum, busname,scaled_power read excel sheet matching year , location busnum,area,power in mydict: power= float(scaled_power) busnum = int(busnum) print('bus #: %d\t' % busnum ,'area station: %s\t'% area,'new load total: %d mw\t' % power) #api changing , scaling generation of loads #psspy.bsys(1,0,[0.0,0.0],0,[],1,[busnum],0,[],0,[]) #psspy.scal_2(1,0,1,[0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0]) #psspy.scal_2(0,1,2,[0,1,0,1,0],[power,0.0,0,-.0,0.0,-.0,0]) #print("\n")
Comments
Post a Comment