You can use f.read() to read the entire file's contents into a string,
providing the file isn't huge. Then, split on "\r" and replace "\n"
when found.
A simple test:
input_data = "abc\rdef\rghi\r\njkl\r\nmno\r\n"
first_split = input_data.split("\r")
for rec in first_split:
rec = rec.replace("\
On Wed, Aug 31, 2011 at 12:37 PM, Alex van der Spek wrote:
> I have a text file that uses both '\r' and '\r\n' end-of-line terminations.
>
> The '\r' terminates the first 25 lines or so, the remainder is termiated
> with '\r\n'
> Is there a way to make it read one line at a time, regardless of th
In <15d8f853-7c87-427b-8f21-e8537bde8...@x12g2000yql.googlegroups.com> Siboniso
Shangase writes:
> i want to type this data in a text file it the same the diffrence is
> the number that only increase and i canot write this up myself since
> it up to 5000 samples
> Data\ja1.wav Data\ja1.mfc
> .
On 01/07/2011 01:19, Siboniso Shangase wrote:
Hi
i m very new to python and i need hepl plz!!
i want to type this data in a text file it the same the diffrence is
the number that only increase and i canot write this up myself since
it up to 5000 samples
Data\ja1.wav Data\ja1.mfc
Data\ja2.wav Da
import os
lst = []
for x in xrange(1, 5001):
lst.append(r"Data\ma{0}.wav Data\ma{0}.mfc".format(x))
lst.insert(x-1, r"Data\ja{0}.wav Data\ja{0}.mfc".format(x))
with open("filename.txt", "w") as fd:
sep = os.linesep
fd.write(sep.join(lst))
On Thu, Jun 30, 2011 at 5:19 PM, Sibonis
On Nov 1, 6:50 pm, "cbr...@cbrownsystems.com"
wrote:
> On Nov 1, 1:58 am, iwawi wrote:
>
>
>
>
>
> > On 1 marras, 09:59, "cbr...@cbrownsystems.com"
>
> > wrote:
> > > On Oct 31, 11:46 pm, iwawi wrote:
>
> > > > On 31 loka, 21:48, Tim Chase wrote:
>
> > > > > > PRJ01001 4 00100END
> > > > > > P
On Nov 1, 1:58 am, iwawi wrote:
> On 1 marras, 09:59, "cbr...@cbrownsystems.com"
>
>
>
> wrote:
> > On Oct 31, 11:46 pm, iwawi wrote:
>
> > > On 31 loka, 21:48, Tim Chase wrote:
>
> > > > > PRJ01001 4 00100END
> > > > > PRJ01002 3 00110END
>
> > > > > I would like to pick only some columns to a
On 1 marras, 09:59, "cbr...@cbrownsystems.com"
wrote:
> On Oct 31, 11:46 pm, iwawi wrote:
>
>
>
>
>
> > On 31 loka, 21:48, Tim Chase wrote:
>
> > > > PRJ01001 4 00100END
> > > > PRJ01002 3 00110END
>
> > > > I would like to pick only some columns to a new file and put them to a
> > > > certain p
On Oct 31, 11:46 pm, iwawi wrote:
> On 31 loka, 21:48, Tim Chase wrote:
>
>
>
> > > PRJ01001 4 00100END
> > > PRJ01002 3 00110END
>
> > > I would like to pick only some columns to a new file and put them to a
> > > certain places (to match previous data) - definition file (def.csv)
> > > could be
On 31 loka, 21:48, Tim Chase wrote:
> > PRJ01001 4 00100END
> > PRJ01002 3 00110END
>
> > I would like to pick only some columns to a new file and put them to a
> > certain places (to match previous data) - definition file (def.csv)
> > could be something like this:
>
> > VARIABLE FIELDSTARTS
On Oct 31, 12:48 pm, Tim Chase wrote:
> > PRJ01001 4 00100END
> > PRJ01002 3 00110END
>
> > I would like to pick only some columns to a new file and put them to a
> > certain places (to match previous data) - definition file (def.csv)
> > could be something like this:
>
> > VARIABLE FIELDSTARTS
Sorry to clarify, I was having issues getting this to work. I'm relatively new
to Python. Sorry for the miscommunication.
> Date: Sun, 31 Oct 2010 16:13:42 -0500
> From: python.l...@tim.thechases.com
> To: brad...@hotmail.com
> CC: python-list@python.org
> Subject: Re: te
On 10/31/10 14:52, Braden Faulkner wrote:
import csv
f = file('def.csv', 'rb')
f.next() # discard the header row
r = csv.reader(f, delimiter=';')
fields = [
(varname, slice(int(start), int(start)+int(size)), width)
for varname, start, size, width
in r
]
I also am having issues with this.
> Date: Sun, 31 Oct 2010 14:48:09 -0500
> From: python.l...@tim.thechases.com
> To: iwawi...@gmail.com
> Subject: Re: text file reformatting
> CC: python-list@python.org
>
> > PRJ01001 4 00100END
> > PRJ01002 3 00110END
> >
PRJ01001 4 00100END
PRJ01002 3 00110END
I would like to pick only some columns to a new file and put them to a
certain places (to match previous data) - definition file (def.csv)
could be something like this:
VARIABLEFIELDSTARTS FIELD SIZE NEW PLACE IN NEW DATA FILE
ProjID ;
On Wed, 2009-10-21, kak...@gmail.com wrote:
> Hello,
> I would like to make a program that takes a text file with the
> following representation:
>
> outlook = sunny
> | humidity <= 70: yes (2.0)
> | humidity > 70: no (3.0)
> outlook = overcast: yes (4.0)
> outlook = rainy
> | windy = TRUE: n
kak...@gmail.com a écrit :
Hello,
I would like to make a program that takes a text file with the
following representation:
outlook = sunny
| humidity <= 70: yes (2.0)
| humidity > 70: no (3.0)
outlook = overcast: yes (4.0)
outlook = rainy
| windy = TRUE: no (2.0)
| windy = FALSE: yes (3.
[EMAIL PROTECTED] wrote:
HI all,
i have some problem with the code belove, i have a list of servers in
a textfile (elencopc.txt) i would to retrieve informations via WMI
( cicle for ), but i don't understand if the code is correct:
Try this, using http://timgolden.me.uk/python/wmi.html :
On Wed, 01 Oct 2008 07:19:44 -0700, yqyq22 wrote:
> My problem is how to translate this vbs in python:
>
> Dim fso
> Dim strComputer
> Set fso = CreateObject("Scripting.FileSystemObject") Set ElencoPC =
> fso.OpenTextFile("elencoPC.txt" , 1, False) Do Until
> ElencoPC.AtEndOfStream
> strComputer =
On Oct 1, 4:03 pm, [EMAIL PROTECTED] wrote:
> HI all,
> i have some problem with the code belove, i have a list of servers in
> a textfile (elencopc.txt) i would to retrieve informations via WMI
> ( cicle for ), but i don't understand if the code is correct:
>
> import win32com.client
> import
Dag a écrit :
> I have an application which works with lists of tuples of the form
> (id_nr,'text','more text',1 or 0). I'll have maybe 20-50 or so of these
> lists containing anywhere from 3 to over 3 tuples. The actions I
> need to do is either append a new tuple to the end of the list, di
On Apr 11, 5:40 pm, Dag <[EMAIL PROTECTED]> wrote:
> I have an application which works with lists of tuples of the form
> (id_nr,'text','more text',1 or 0). I'll have maybe 20-50 or so of these
> lists containing anywhere from 3 to over 3 tuples. The actions I
> need to do is either append a
John Machin a écrit :
(snip)
> ... and a few more cents:
>
> There are *two* relations/tables involved (at least): a "tuple" table
> and a "list" table.
Mmm... From a purely technical POV, not necessarily. If there's no need
for anything else than distinguishing between different lists, a singl
On Apr 12, 7:09 am, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
> Dag a écrit :
>
>
>
> > I have an application which works with lists of tuples of the form
> > (id_nr,'text','more text',1 or 0). I'll have maybe 20-50 or so of these
> > lists containing anywhere from 3 to over 3 tuples. Th
Dag a écrit :
> I have an application which works with lists of tuples of the form
> (id_nr,'text','more text',1 or 0). I'll have maybe 20-50 or so of these
> lists containing anywhere from 3 to over 3 tuples. The actions I
> need to do is either append a new tuple to the end of the list, di
En Wed, 11 Apr 2007 13:40:02 -0300, Dag <[EMAIL PROTECTED]> escribió:
> I have an application which works with lists of tuples of the form
> (id_nr,'text','more text',1 or 0). I'll have maybe 20-50 or so of these
> lists containing anywhere from 3 to over 3 tuples. The actions I
> need to do
Peter Otten, your solution is very nice, it uses groupby splitting on
empty lines, so it doesn't need to read the whole files into memory.
But Daniel Nogradi says:
> But the names of the fields (node, x, y) keeps changing from file to
> file, even their number is not fixed, sometimes it is (node,
> > I have an awk program that parses a text file which I would like to
> > rewrite in python. The text file has multi-line records separated by
> > empty lines and each single-line field has two subfields:
> >
> > node 10
> > x -1
> > y 1
> >
> > node 11
> > x -2
> > y 1
> >
> > node 12
> > x -3
>
Daniel Nogradi wrote:
> I have an awk program that parses a text file which I would like to
> rewrite in python. The text file has multi-line records separated by
> empty lines and each single-line field has two subfields:
>
> node 10
> x -1
> y 1
>
> node 11
> x -2
> y 1
>
> node 12
> x -3
> y
29 matches
Mail list logo