problem with read() function in python

Started by
16 comments, last by ForD 17 years ago
Quote:Original post by ForD
Quote:Original post by Oluseyi
Show us more code. Like the buffer you read into and what you do with it, and whether you also try to write to the file, etc. Show us your whole program.

That is all of my code. That's literally all I'm trying to do, open file and read it. Nothing more.


If it doesn't appear to be "hanging", then it's not a problem with blocking.

I take it you are doing this at the interactive prompt (so that you can see the value of the expression 'x.read()')?

What kind of file is it? What are you expecting to see, and why? What does it look like if you open it in a text editor (such as Notepad)?

Advertisement
Quote:Original post by Zahlman
Quote:Original post by ForD
Quote:Original post by Oluseyi
Show us more code. Like the buffer you read into and what you do with it, and whether you also try to write to the file, etc. Show us your whole program.

That is all of my code. That's literally all I'm trying to do, open file and read it. Nothing more.


If it doesn't appear to be "hanging", then it's not a problem with blocking.

I take it you are doing this at the interactive prompt (so that you can see the value of the expression 'x.read()')?

What kind of file is it? What are you expecting to see, and why? What does it look like if you open it in a text editor (such as Notepad)?

Yes, I'm doing it through IDLE.

Its a plugin file for a game tht I've made a text file, so I'm expecting to see some data that tells the game to do certain things. If I open it up in notepad,I see this data, if I use the read() function, I only see the first prt of the data. But, like I said before, the read() function was working just fine a couple of nights ago.
Quote:Original post by ForD
That is all of my code. That's literally all I'm trying to do, open file and read it. Nothing more.

Quote:Original post by ForD
Its a plugin file for a game tht I've made a text file, so I'm expecting to see some data that tells the game to do certain things. If I open it up in notepad,I see this data, if I use the read() function, I only see the first prt of the data. But, like I said before, the read() function was working just fine a couple of nights ago.

Interesting. When was the text file last modified? The first thing that comes to mind is that you've inadvertently introduced an EOF into the text file somewhere (though why Notepad shows it in entirety is a good question). Can you upload the text file and let us test a simple read from the interactive shell?
Sure thing, here's a link to download it: http://www.divshare.com/download/294913-1d6
Looks like a Unicode problem, specifically a codepage mismatch. What was the original encoding of the file?
Quote:Original post by Oluseyi
Looks like a Unicode problem, specifically a codepage mismatch. What was the original encoding of the file?

Latin-1 I believe. What's a codepage mismatch?
Did you try f = open("test.txt", "rb")

You are reading a binary file.
Quote:Original post by Antheus
Did you try f = open("test.txt", "rb")

You are reading a binary file.

Thank you, that worked perfectly.

This topic is closed to new replies.

Advertisement