473,516 Members | 3,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Behaviour of filehandle.readlines() for images on Windows


Hi!
I'm trying to get a specific information from inside an image and it
works correctly on unices. What I do is:

1. associate a filehandle with the image file
2. get the desired line
3. read the amount of data I want
4. close the filehandle
While using Windows it only gets the first line with the signature of
the file. Any ideas on how to accomplish the same task?

I'm wondering if it has something to do with either (or both) the
magic treatment Windows gives to files trying to open them with some
specific program or the line ending convention (these images show fine
on Windows but were generated on a Linux box).
TIA,
--
Godoy. <go***@metalab.unc.edu>
Jul 18 '05 #1
2 2182
Jorge Godoy wrote:
I'm trying to get a specific information from inside an image and it
works correctly on unices. What I do is:

1. associate a filehandle with the image file
2. get the desired line
3. read the amount of data I want
4. close the filehandle
While using Windows it only gets the first line with the signature of
the file. Any ideas on how to accomplish the same task?

I'm wondering if it has something to do with either (or both) the
magic treatment Windows gives to files trying to open them with some
specific program or the line ending convention (these images show fine
on Windows but were generated on a Linux box).


Assuming it's the latter issue, which seems most likely, open the
file with option 'rb' for "reading binary". E.g.,

myfile = file('foo.jpg', 'rb')

it's doubtful that you want to use readlines on a binary file, though.
Alex

Jul 18 '05 #2
Alex Martelli <al***@aleax.it> writes:
Assuming it's the latter issue, which seems most likely, open the
file with option 'rb' for "reading binary". E.g.,

myfile = file('foo.jpg', 'rb')

it's doubtful that you want to use readlines on a binary file, though.


That's what I was looking for but didn't remember that I could open it
in a binary way. :-\ I was looking for something like a rawread() in
the docs, believe it or not. We tend do look for answers the hardest
way :-)

With regards to using readlines, I'm using it to get some information
that is readable in text format and that happens to be stored on a PNG
image. I was thinking about using something to read the 'n' bytes I
need but the binary flag solved my problem.
Thank you very much.

--
Godoy. <go***@metalab.unc.edu>
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11515
by: Leeds, Mark | last post by:
I did more investigation into my previous problem and what happens is that my text file has \r for representing a new line instead of a \n. is there a way to tell the readlines function that the symbol for a newline is \r rather than \n ? right now the readlines function reads the\r as another item in the list and just puts everything into...
2
6193
by: Yong Wang | last post by:
Hi, I use readlines() to read one data file. Python automatically parses the read contents into a list of lines. When I used list to print out the 1st line, it is ok. When I use the list index 2 to print out the 2nd line , there is an error mesage. I only need one line of input data file in the middle of the file. For example, I have data file...
9
29207
by: wordsender | last post by:
Hey guys, I can't figure this one out, why is this simple script giving me problems? logfile=file(r'test.txt','w') logfile.write('datetime') test=logfile.readlines() When I run it I get the error message:
2
4139
by: vch | last post by:
Does a call to file.readlines() reads all lines at once in the memory? Are the any reasons, from the performance point of view, to prefer *while* loop with readline() to *for* loop with readlines()?
1
1281
by: Christoph | last post by:
Hi I have different images which i use to simulate a button behaviour. This looks as follows: if (document.images) { toc1over = new Image(31,54); toc1over.src = "b go focus.bmp"; toc1down= new Image(31,54);
34
2760
by: Ross Reyes | last post by:
HI - Sorry for maybe a too simple a question but I googled and also checked my reference O'Reilly Learning Python book and I did not find a satisfactory answer. When I use readlines, what happens if the number of lines is huge? I have a very big file (4GB) I want to read in, but I'm sure there must be some limitation to readlines and...
1
1241
by: Wijaya Edward | last post by:
Hi all, I have the following code: import sys import re ham_count = 0 spam_count = 0
7
4075
by: Wojciech Gryc | last post by:
Hi, I'm currently using Python to deal with a fairly large text file (800 MB), which I know has about 85,000 lines of text. I can confirm this because (1) I built the file myself, and (2) running a basic Java program to count lines yields a number in that range. However, when I use Python's various methods -- readline(), readlines(), or...
5
6210
by: zxo102 | last post by:
Hello All, I have a system. An instrument attched to 'com1' is wireless connected to many sensors at different locations. The instrument can forward the "commands" (from pyserial's write()) to those sensors. Based on the "commands", the sensors keep sending corresponding data back to the instrument which wraps up those data and put into...
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.