Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 3 years ago.
I passing a csv file path into this function.
def validateCSV(filename):
with open(filename, 'rb') as file:
print type(filename)
if not filename.readlines():
print 'empty file'
else:
reader = csv.reader(file)
for row in reader:
print row
file.close()
but when I run this I got an error
'unicode' object has no attribute 'readlines'
but when I check the type of the csv file it is unicode. So I understood that they need a file object.So how can I convert unicode to file object. Then i tried this,
filename = filename.encode("utf-8")
then its type becomes string and shows another error.
'str' object has no attribute 'readlines'
Please help me.Thanks in advance.