TypeError: a bytes-like object is required, not ‘str’ in python and CSV
You are using Python 2 methodology instead of Python 3. Change: outfile=open(‘./immates.csv’,’wb’) To: outfile=open(‘./immates.csv’,’w’) and you will get a file with the following output: SNo,States,Dist,Population 1,Andhra Pradesh,13,49378776 2,Arunachal Pradesh,16,1382611 3,Assam,27,31169272 4,Bihar,38,103804637 5,Chhattisgarh,19,25540196 6,Goa,2,1457723 7,Gujarat,26,60383628 ….. In Python 3 csv takes the input in text mode, whereas in Python 2 it took it in binary mode. … Read more