Re: Text Processing

2011-12-22 Thread Yigit Turgut
On Dec 21, 2:01 am, Alexander Kapps wrote: > On 20.12.2011 22:04, Nick Dokos wrote: > > > > > > > > > > >>> I have a text file containing such data ; > > >>>          A                B                C > >>> --- > >>> -2.0100e-01    8.000e-02  

Re: Text Processing

2011-12-20 Thread Alexander Kapps
On 20.12.2011 22:04, Nick Dokos wrote: I have a text file containing such data ; ABC --- -2.0100e-018.000e-028.000e-05 -2.e-010.000e+00 4.800e-04 -1.9900e-014.000e-021.600e-04

Re: Text Processing

2011-12-20 Thread Nick Dokos
Jérôme wrote: > Tue, 20 Dec 2011 11:17:15 -0800 (PST) > Yigit Turgut a écrit: > > > Hi all, > > > > I have a text file containing such data ; > > > > ABC > > --- > > -2.0100e-018.000e-028.000e-0

Re: Text Processing

2011-12-20 Thread Jérôme
Tue, 20 Dec 2011 11:17:15 -0800 (PST) Yigit Turgut a écrit: > Hi all, > > I have a text file containing such data ; > > ABC > --- > -2.0100e-018.000e-028.000e-05 > -2.e-010.000e+00 4.800

Re: Text Processing

2011-12-20 Thread Dave Angel
On 12/20/2011 02:17 PM, Yigit Turgut wrote: Hi all, I have a text file containing such data ; ABC --- -2.0100e-018.000e-028.000e-05 -2.e-010.000e+00 4.800e-04 -1.9900e-014.000e-02

Re: text processing SOLVED

2008-09-27 Thread [EMAIL PROTECTED]
Thanks Black Jack Working -- http://mail.python.org/mailman/listinfo/python-list

Re: text processing

2008-09-25 Thread Paul McGuire
On Sep 25, 9:51 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have string like follow > 12560/ABC,12567/BC,123,567,890/JK > > I want above string to group like as follow > (12560,ABC) > (12567,BC) > (123,567,890,JK) > > i try regular expression i am able to get first two not the third one.

Re: text processing

2008-09-25 Thread MRAB
On Sep 25, 6:34 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Thu, 25 Sep 2008 15:51:28 +0100, [EMAIL PROTECTED] wrote: > > I have string like follow > > 12560/ABC,12567/BC,123,567,890/JK > > > I want above string to group like as follow (12560,ABC) > > (12567,BC) > > (123,567,890,JK

Re: text processing

2008-09-25 Thread kib2
You can do it with regexps too : >-- import re to_watch = re.compile(r"(?P\d+)[/](?P[A-Z]+)") final_list = to_watch.findall("12560/ABC,12567/BC,123,567,890/JK") for number,word in final_list : print "number:%s -- word: %s"%(num

Re: text processing

2008-09-25 Thread Marc 'BlackJack' Rintsch
On Thu, 25 Sep 2008 15:51:28 +0100, [EMAIL PROTECTED] wrote: > I have string like follow > 12560/ABC,12567/BC,123,567,890/JK > > I want above string to group like as follow (12560,ABC) > (12567,BC) > (123,567,890,JK) > > i try regular expression i am able to get first two not the third one. > ca

Re: Text processing and file creation

2007-09-07 Thread Paddy
On Sep 7, 3:50 am, George Sakkis <[EMAIL PROTECTED]> wrote: > On Sep 5, 5:17 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > If this was a code golf challenge, I'd choose the Unix split solution and be both maintainable as well as concise :-) - Paddy. -- http://mail.python.org/mailman/li

Re: Text processing and file creation

2007-09-06 Thread George Sakkis
On Sep 5, 5:17 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Sep 5, 1:28 pm, Paddy <[EMAIL PROTECTED]> wrote: > > > On Sep 5, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > > I have a text source file of about 20.000 lines.>From this file, I like > > > to write the fir

Re: Text processing and file creation

2007-09-06 Thread Ricardo Aráoz
Shawn Milochik wrote: > On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> I have a text source file of about 20.000 lines. >> >From this file, I like to write the first 5 lines to a new file. Close >> that file, grab the next 5 lines write these to a new file... grabbing >> 5 lines and cre

Re: Text processing and file creation

2007-09-06 Thread Shawn Milochik
Here's my solution, for what it's worth: #!/usr/bin/env python import os input = open("test.txt", "r") counter = 0 fileNum = 0 fileName = "" def newFileName(): global fileNum, fileName while os.path.exists(fileName) or fileName == "": fileNum += 1 x = "%0.5d" % fileN

Re: Text processing and file creation

2007-09-06 Thread Arnau Sanchez
[EMAIL PROTECTED] escribió: > I am still wondering how to do this efficiently in Python (being kind > of new to it... and it's not for homework). You should post some code anyway, it would be easier to give useful advice (it would also demonstrate that you put some effort on it). Anyway, here i

Re: Text processing and file creation

2007-09-06 Thread Alberto Griggio
> Thanks for making me aware of the (UNIX) split command (split -l 5 > inFile.txt), it's short, it's fast, it's beautiful. > > I am still wondering how to do this efficiently in Python (being kind > of new to it... and it's not for homework). Something like this should do the job: def nlines(num

Re: Text processing and file creation

2007-09-05 Thread Arnaud Delobelle
On Sep 6, 12:46 am, Steve Holden <[EMAIL PROTECTED]> wrote: > Arnaud Delobelle wrote: [...] > > print "all done!" # All done > > print "Now there are 4000 files in this directory..." > > > Python 3.0 - ready (I've used open() instead of file()) > > bzzt! > > Python 3.0a1 (py3k:57844, Aug 31

Re: Text processing and file creation

2007-09-05 Thread Ginger
and u can parse lines from read buffer freely. have fun! - Original Message - From: "Shawn Milochik" <[EMAIL PROTECTED]> To: Sent: Thursday, September 06, 2007 1:03 AM Subject: Re: Text processing and file creation > On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTE

Re: Text processing and file creation

2007-09-05 Thread Steve Holden
Arnaud Delobelle wrote: [...] > from my_useful_functions import new_file, write_first_5_lines, > done_processing_file, grab_next_5_lines, another_new_file, write_these > > in_f = open('myfile') > out_f = new_file() > write_first_5_lines(in_f, out_f) # write first 5 lines > close(out_f) > while not

Re: Text processing and file creation

2007-09-05 Thread Arnaud Delobelle
On Sep 5, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have a text source file of about 20.000 lines.>From this file, I like to > write the first 5 lines to a new file. Close > > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files

Re: Text processing and file creation

2007-09-05 Thread [EMAIL PROTECTED]
On Sep 5, 1:28 pm, Paddy <[EMAIL PROTECTED]> wrote: > On Sep 5, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > I have a text source file of about 20.000 lines.>From this file, I like to > > write the first 5 lines to a new file. Close > > > that file, grab the next 5 lines write t

Re: Text processing and file creation

2007-09-05 Thread Paddy
On Sep 5, 5:13 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have a text source file of about 20.000 lines.>From this file, I like to > write the first 5 lines to a new file. Close > > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files

Re: Text processing and file creation

2007-09-05 Thread James Stroud
[EMAIL PROTECTED] wrote: > I have a text source file of about 20.000 lines. >>From this file, I like to write the first 5 lines to a new file. Close > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files until processing of all 20.000 lines is > do

Re: Text processing and file creation

2007-09-05 Thread kyosohma
On Sep 5, 11:57 am, Bjoern Schliessmann wrote: > [EMAIL PROTECTED] wrote: > > I would use a counter in a for loop using the readline method to > > iterate over the 20,000 line file. > > file objects are iterables themselves, so there's no need to do that > by using a method. Very true! Darn it!

Re: Text processing and file creation

2007-09-05 Thread Shawn Milochik
On 9/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I have a text source file of about 20.000 lines. > >From this file, I like to write the first 5 lines to a new file. Close > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files until proces

Re: Text processing and file creation

2007-09-05 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote: > I would use a counter in a for loop using the readline method to > iterate over the 20,000 line file. file objects are iterables themselves, so there's no need to do that by using a method. > Reset the counter every 5 lines/ iterations and close the file. I'd use a

Re: Text processing and file creation

2007-09-05 Thread Arnau Sanchez
[EMAIL PROTECTED] escribió: > I have a text source file of about 20.000 lines. >>From this file, I like to write the first 5 lines to a new file. Close > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files until processing of all 20.000 lines is

Re: Text processing and file creation

2007-09-05 Thread kyosohma
On Sep 5, 11:13 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have a text source file of about 20.000 lines.>From this file, I like to > write the first 5 lines to a new file. Close > > that file, grab the next 5 lines write these to a new file... grabbing > 5 lines and creating new files

Re: text processing problem

2005-04-08 Thread Leif K-Brooks
Maurice LING wrote: I'm looking for a way to do this: I need to scan a text (paragraph or so) and look for occurrences of " ()". That is, if the text just before the open bracket is the same as the text in the brackets, then I have to delete the brackets, with the text in it. How's this? import

Re: text processing problem

2005-04-08 Thread Matt
Maurice LING wrote: > Matt wrote: > > I'd HIGHLY suggest purchasing the excellent > href="http://www.oreilly.com/catalog/regex2/index.html";>Mastering > > Regular Expressions by Jeff Friedl. Although it's mostly geared > > towards Perl, it will answer all your questions about regular > > express

Re: text processing problem

2005-04-07 Thread Paul McGuire
Maurice - Here is a pyparsing treatment of your problem. It is certainly more verbose, but hopefully easier to follow and later maintain (modifying valid word characters, for instance). pyparsing implicitly ignores whitespace, so tabs and newlines within the expression are easily skipped, withou

Re: text processing problem

2005-04-07 Thread Maurice LING
Matt wrote: I'd HIGHLY suggest purchasing the excellent http://www.oreilly.com/catalog/regex2/index.html";>Mastering Regular Expressions by Jeff Friedl. Although it's mostly geared towards Perl, it will answer all your questions about regular expressions. If you're going to work with regexs, this

Re: text processing problem

2005-04-07 Thread Matt
Maurice LING wrote: > Matt wrote: > > > > > > Try this: > > import re > > my_expr = re.compile(r'(\w+) (\(\1\))') > > s = "this is (is) a test" > > print my_expr.sub(r'\1', s) > > #prints 'this is a test' > > > > M@ > > > > Thank you Matt. It works out well. The only think that gives it problem >

Re: text processing problem

2005-04-07 Thread Maurice LING
Matt wrote: Try this: import re my_expr = re.compile(r'(\w+) (\(\1\))') s = "this is (is) a test" print my_expr.sub(r'\1', s) #prints 'this is a test' M@ Thank you Matt. It works out well. The only think that gives it problem is in events as "there (there)", where between the word and the same

Re: text processing problem

2005-04-07 Thread Matt
Maurice LING wrote: > Hi, > > I'm looking for a way to do this: I need to scan a text (paragraph or > so) and look for occurrences of " ()". That is, if the > text just before the open bracket is the same as the text in the > brackets, then I have to delete the brackets, with the text in it. > >