1

I have a function converts csv to excel. While converting csv to excel python script got failed due to below issue

Error: _csv.Error: line contains NULL byte

I have referred a link from stack overflow ("Line contains NULL byte" in CSV reader (Python)) and i found below solution

def fix_nulls(s):
    for line in s:
        yield line.replace('\0', ' ')

r = csv.reader(fix_nulls(open(...)))

Can any one help me what "YIELD" function will do ..

\0 is meant for nulls and nulls are getting replaced with space. 

But i am not sure what is "YIELD" function will do.. Is this a better solution or any other suggestions.

Arya
  • 528
  • 6
  • 26
  • Did you try this, and does it work for you? Also, to get to the real root of the problem, are you sure that you are using the correct encoding to read your file? Could it be some UTF-16, or whatever? – Thierry Lathuille Oct 20 '19 at 08:40
  • @ThierryLathuille. Thanks a lot for the reply. Yes it worked.. But not 100% confidence what doesn Yield function do – Arya Oct 20 '19 at 09:29
  • `yield` is not the problem here. Using it in a function turns it into a generator, but if you don't want to go into details, you cant just view it as a simple `return` here. What I would be more concerned about is why the data contains null bytes, and whether removing them this way won't corrupt the data. But well, if you checked it and it is ok... – Thierry Lathuille Oct 20 '19 at 09:33

0 Answers0