Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
80 views
in Technique[技术] by (71.8m points)

Python read() only returns partial file

I'm working on a script that reads in a text and processes, pretty straight forward stuff I do all the time. However, this time it only reads in about 512 lines of a file that is tens of thousands of lines long. The file doesn't look truncated or anything so there must be a stray EOF in the file. How do I work around this? Here is a little code snippet I put together to troubleshoot this:

objFileIn = open(strFilein, "r")
strJson = objFileIn.read()
objFileOut = open(strFixedjason,"w")
objFileOut.write(strJson)
objFileOut.close()
objFileIn.close()

strFilein points to a json file that is 20,550 lines long. strFixedjason has 512 lines in it.

question from:https://stackoverflow.com/questions/65921773/python-read-only-returns-partial-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK this is totally embarrassing, turns out I wasn't feeding the script the file I thought I was processing :-( I two files with the exact same name in two different directories, one was 512 lines the other 20K lines. I pointed the script at the smaller one and looked at the other in the editor. You can classify this question as caused by stupid human error. :-P


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...