Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread Dhruv Baldawa
Sorry, I just hit the TAB key, and the message got delivered. I am not sure if this is what you want. If it is then to accomplish this, you will need to read the entire file first, and then compile the regex. Iterate using finditer(), and take the groupdict() to get all the values. Also, I have typ

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread Dhruv Baldawa
regex = """# #(?P[a-zA-Z]+) # Population = (?P\d+)cr Temperature = (?P\d+) deg cel Area = (?P\d+) sqft""" regex = re.compile(regex, flags=re.MULTILINE) print regex.findall(rstr) # >>> [('Delhi', '7', '10', '13000'), ('Mumbai', '10', '30', '132000')] for x in regex.finditer(rstr): group = x.g

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread Rahul R
Hey David, Assuming , its not a continuous stream of data being written to file all the time. you could do something like this https://gist.github.com/4477268 . you can enhance it and make it more pythonic. :) Thanks, Rahul On Mon, Jan 7, 2013 at 5:02 PM, davidsnt wrote: > No this file ch

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread Syed Mushtaq
What do you really want to do * * http://mywiki.wooledge.org/XyProblem On Mon, Jan 7, 2013 at 5:02 PM, davidsnt wrote: > No this file changes very often, like once in 5 minutes and the values are > updated, also there is no way I can move it to a database. > > Regards, > Davidsanthosh L > > >

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread davidsnt
No this file changes very often, like once in 5 minutes and the values are updated, also there is no way I can move it to a database. Regards, Davidsanthosh L On Mon, Jan 7, 2013 at 4:55 PM, Amit Sethi wrote: > On Mon, Jan 7, 2013 at 3:52 PM, davidsnt wrote: > > Gora, > > > > Can you help me w

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread Amit Sethi
On Mon, Jan 7, 2013 at 3:52 PM, davidsnt wrote: > Gora, > > Can you help me with few links that you have handy to which I can refer to > build a parser instead of RE Can you elaborate on the idea of "build a parser" , in any case you will have to use regex. > I also need this app to be >able to

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread steve
On Monday 07 January 2013 03:06 PM, davidsnt wrote: Bangpypers, Having a little trouble in parsing a file of 702 line appox, the file is in the format [...snip...] Could you show us what you already have done ? cheers, - steve ___ BangPypers maili

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread davidsnt
Gora, Can you help me with few links that you have handy to which I can refer to build a parser instead of RE Regards, Davidsanthosh L On Mon, Jan 7, 2013 at 3:38 PM, Gora Mohanty wrote: > On 7 January 2013 15:06, davidsnt wrote: > > Bangpypers, > > > > Having a little trouble in parsing a f

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread Gora Mohanty
On 7 January 2013 15:38, Gora Mohanty wrote: > import re > TITLE_RE = re.compile( r'#\n#([^\n]*)\n#\n \n\[([^\]]*)\]\n \n', > re.MULTILINE|re.DOTALL ) > for m in TITLE_RE.finditer( s.strip ): > title, info = m.groups() > print title, info Oops, that should be s.strip(), viz., import re

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread davidsnt
I am trying with re.split to split the file based on the pattern but stuck at the point where I am unable to move forward, I also need this app to be able to do a search in the file based on the title. Regards, Davidsanthosh L On Mon, Jan 7, 2013 at 3:21 PM, steve wrote: > On Monday 07 January

Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread Gora Mohanty
On 7 January 2013 15:06, davidsnt wrote: > Bangpypers, > > Having a little trouble in parsing a file of 702 line appox, > > the file is in the format > > # > # > # > [Space] > [ > > Few lines of information about the title > > ] > > [Space] If the above format is strictly followed, this should d

[BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread davidsnt
Bangpypers, Having a little trouble in parsing a file of 702 line appox, the file is in the format # # # [Space] [ Few lines of information about the title ] [Space] # # # [Space] [ Few lines of information about the title ] I want to read this file block by block, the need is build a d