Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
81 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...