i have made program stores score attached name in .txt file. however, want print alphabetical order of name attached score. when run program come error io.unsupportedoperation: not writable here code: file = open(class_name , 'r') #opens file in 'append' mode don't delete information name = (name) file.write(str(name + " : " )) #writes information file file.write(str(score)) file.write('\n') linelist = file.readlines() line in sorted(linelist): print(line.rstrip()); file.close() you have opened file read only, attempted write it. file left open, attempt read it, if in append mode, file pointer @ end of file. try instead: class_name = "class.txt" name = "joe" score = 1.5 file = open(class_name , 'a') #opens file in 'append' mode don't delete information name = (n...
i looking select values 1 column distinct using peewee. for example if had table organization year company_1 2000 company_1 2001 company_2 2000 .... to return unique values in organization column [i.e. company_1 , company_2 ] i had assumed possible using distinct option documented http://docs.peewee-orm.com/en/latest/peewee/api.html#selectquery.distinct my current code: organizations_returned = organization_db.select().distinct(organization_db.organization_column).execute() item in organizations_returned: print (item.organization_column) does not result in distinct rows returned (it results in e.g. company_1 twice). the other option tried: organization_db.select().distinct([organization_db.organization_column]).execute() included [ ] within disctinct option, although appearing more consistent documentation, resulted in error peewee.operationalerror: near "on": syntax error : am correct in ...
Comments
Post a Comment