473,287 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Readline and record separator

Is it possible to change record separator when using readline?
As far as I know readline reads characters until found '\n' and it is
the end of record for readline.
My problem is that my record consits several '\n' and when I use
readline it does NOT read the whole my record.
So If I could change '\n' as a record separator for readline, it
would solve my problem.
Any idea?
Thank you
L.

Oct 30 '07 #1
7 5232
If it's a short file you could slurp the entire file and then split it
however you like using regular expressions.

I'm not sure if you can alter it, but os.linesp holds the value that
is accessed when file.readlines() splits lines. Conceivably, if it
were set to 'FOO', 'FOO' would be used to determine the EOL string.

Oct 30 '07 #2
On 2007-10-30, Johny <py****@hope.czwrote:
Is it possible to change record separator when using readline?
As far as I know readline reads characters until found '\n' and it is
the end of record for readline.
My problem is that my record consits several '\n' and when I use
readline it does NOT read the whole my record.
So If I could change '\n' as a record separator for readline, it
would solve my problem.
Any idea?
Read large enough blocks of data, then use block.find() (in the string module)
to find your delimiter, and split the block.

Albert

Oct 30 '07 #3
On Oct 30, 12:21 pm, Johny <pyt...@hope.czwrote:
Is it possible to change record separator when using readline?
As far as I know readline reads characters until found '\n' and it is
the end of record for readline.
My problem is that my record consits several '\n' and when I use
readline it does NOT read the whole my record.
So If I could change '\n' as a record separator for readline, it
would solve my problem.
Any idea?
Thank you
L.
I'm not aware any such a method. But what you could do is simply read
all of them(readlines()) and then split it(delimeter would be your new
line)

Oct 30 '07 #4
On Oct 30, 8:21 am, Johny <pyt...@hope.czwrote:
Is it possible to change record separator when using readline?
As far as I know readline reads characters until found '\n' and it is
the end of record for readline.
My problem is that my record consits several '\n' and when I use
readline it does NOT read the whole my record.
So If I could change '\n' as a record separator for readline, it
would solve my problem.
Any idea?
Thank you
L.
Check out this recipe, it's pretty generic:
http://aspn.activestate.com/ASPN/Coo.../Recipe/521877.

George

Oct 30 '07 #5
On Oct 30, 7:21 am, Johny <pyt...@hope.czwrote:
My problem is that my record consits several '\n' and when I use
readline it does NOT read the whole my record.
So If I could change '\n' as a record separator for readline, it
would solve my problem.
Python Cookbook (great book!) 2nd Ed pg. 717: "Iterating on a Stream
of Data Blocks as a Stream of Lines."

Allows you to specify both eol for source and output file.

rd

Oct 30 '07 #6
Jeff a écrit :
If it's a short file you could slurp the entire file and then split it
however you like using regular expressions.
My my my...
I'm not sure if you can alter it,
You can. But it hopefully won't alter your binary-compiled system libs.
IOW : it's so (obviously) useless that no one even bothered doing
anything to prevent you from altering it !-)

but os.linesp
os.line
holds the value that
is accessed when file.readlines() splits lines. Conceivably, if it
were set to 'FOO', 'FOO' would be used to determine the EOL string.
Hopefully not. Anyway, the answer is elsewhere (hint: import csv).

Oct 30 '07 #7
Dennis Lee Bieber a écrit :
On Wed, 31 Oct 2007 11:13:21 +0100, Bruno Desthuilliers
<br********************@wtf.websiteburo.oops.comde claimed the
following in comp.lang.python:
>[1] Coma Separated Values - but the separator can be almost anything.
Comma...
oops...
though at this time of night I feel like I should be in a
coma <G>
Nov 2 '07 #8

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

Similar topics

1
by: Morten | last post by:
Hi. I have a file using \n as line-separator. There are also occurrences of \r in the file, but I don't want the BufferedReader.readLine() to consider those as EOL. Apart from stripping all \r...
12
by: Mike Maxwell | last post by:
When I invoke readline() in a for loop, why does it return a series of one-char strings, rather than the full line? >>> for sL in sys.stdin.readline(): print sL .... abc a b c
16
by: Douglas | last post by:
Gday, How would I format a number so that: TheValue = 32500 Displays in the TextBox as: $32,500.00
3
by: Angelic Devil | last post by:
I know this has been asked before (I already consulted the Google Groups archive), but I have not seen a definative answer. Is there a way to change the record separator in readlines()? The...
1
by: Jian Qiu | last post by:
Hi, I tried to install python2.4.2. Unfortunately building 'readline' extension failed. Here is what I got: (It is a bit long. If you are impatient, please look at the end where it reports the...
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
7
by: Eric | last post by:
I am trying to save the "last read" position of a file using a StreamReader object. I am reading the lines of the file using StreamReader.ReadLine and then saving the current position in the...
6
by: HMS Surprise | last post by:
I need to write 2 member lists to a file. For each record the number of these lists can be different. I think a good way to handle that may be to make each record a list of lists. I am restricted...
6
by: Lee Sander | last post by:
Dear all, I would like to read a really huge file that looks like this: line_11 line_12 line_13 .... line_21 line_22 ....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.