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. 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.
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
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)
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
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
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).
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>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
|
by: Douglas |
last post by:
Gday,
How would I format a number so that:
TheValue = 32500
Displays in the TextBox as: $32,500.00
|
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...
|
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...
|
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:
...
|
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...
|
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...
|
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
....
|
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...
|
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"....
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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)...
| |