472,350 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,350 software developers and data experts.

Re: Reading a file

aditya shukla wrote:
I have a text file whose contents are like this:-


I am trying to read the file like this:-
>x = open("c:\\a.txt","r")
Better to use "rb" (for binary read) rather than "r" mode.
Now, tell us what you *really* did. Not that -- that would read the
contents of the file, put throw the returned result away.
You must have done something like

c = x.read()
the result that i get is ike this:-
'jd|fj|dnv|jd|0.33|c:\\\\windows\\\\win32\nshcbsbs |nscsjsj|0.93|hsbcjsnc\n'

My doubt is how can i read the file as it is?
You *have* read the file as it is. Examine each character, and you'll
see that the string is exactly as you expect.

However, your output to the screen is escaping some character with
backslashes. But that's just because of the method you used to print to
the screen.

What method *did* you use to print?

If you just typed the variable into which you had read the contents,
then you get the equivalent of

print repr(c)
which explains the escapes.

print c
and that won't happen.
Gary Herron
ie my output should be

Thanks in advance

Jul 24 '08 #1
0 818

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

Similar topics

by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it...
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much...
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the...
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is...
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format....
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.