Why wont python read a download file






















Improve this question. Reading line by line with an iterator should be a lazy operation, so it should work regardless to the size of the file. While it shouldn't affect your situation, you will also want to use with when opening files - it's a good practice than handles closing under exceptions correctly. That worked great! Thanks so much. Have you tried it with a different large text file? Is there something strange with the file mb in - some strange character that is being treated as the end of file?

I have. I thought it might have been the file at first, but I tried it with ones of varying size from various sources. The large I tried was 2. There's no reason your original code shouldn't have worked. It's also "lazy" as Latty calls it. You shouldn't need to write your own iterator, or to read in chunks. Show 2 more comments. Active Oldest Votes. You can also specify the mode when using fileinput : fileinput. Improve this answer.

That also works! I like that solution the most, because how easy it is to change the existing code. This is because the simplest method of doing what you want to do is to simply use.

To exercise this useful technique, create a directory in which to place dynamic files that should be displayed rather than executed, and add the following line of code to the htaccess file belonging to that directory. This method is known to work for. Here it is:. In your case, since it is only the. The main article has a lot of other useful. In the example he cited, the file has a. Active 3 months ago.

Viewed 12k times. Improve this question. Gama11 Val Kobilaski Val Kobilaski 21 1 1 gold badge 1 1 silver badge 2 2 bronze badges. Are you using the absolute path to the file? To add on to what JacobIRR is asking, perhaps the execution directory is not what you think it is and is different between IDEs, which would explain Idle vs Code discrepancies. If that's the case, adding the exact FileNotFound error and your directory structure will help us diagnose the issue.

JacobIRR: file is not keyword for python 3. Just saying. Rahul did not realize that, thanks — JacobIRR. In VS code relative path works. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.

Post as a guest Name. Email Required, but never shown. The Overflow Blog. Introducing Content Health, a new way to keep the knowledge base up-to-date. Podcast what if you could invest in your favorite developer? Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer. Related Hot Network Questions.



0コメント

  • 1000 / 1000