472,958 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 5188
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 ....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.