[Tutor] Python regular expression

Rick Muller rick_muller at yahoo.com
Fri Dec 3 22:34:17 CET 2004


The file type you mention is also called an INI file,
and is used for Windows initialization scripts, among
other things.

There's a nice recipe on this in the Python Cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65334

This will read your file in as a dictionary. You can
then do searches through lists of the keys:

mydict = LoadConfig(file.ini)
for key in mydict.keys():
    if re.search(key,"_at"): do_something(mydict[key])


--- kumar s <ps_python at yahoo.com> wrote:

> Dear group, 
> 
> I have a file with 645,984 lines.  This file is
> composedcompletely of bocks.
> 
> For e.g.
> 
> [Unit111]
> Name=NONE
> Direction=2
> NumAtoms=16
> NumCells=32
> UnitNumber=111
> UnitType=3
> NumberBlocks=1
> 
> [Unit111_Block1]
> Name=31318_at
> BlockNumber=1
> NumAtoms=16
> NumCells=32
> StartPosition=0
> StopPosition=15
> CellHeader=X	Y	PROBE	FEAT	QUAL	EXPOS	POS	CBASE	PBASE
> TBASE	ATOM	INDEX	CODONIND	CODON	REGIONTYPE	REGION
> Cell1=24	636	N	control	31318_at	0	13	A	A	A	0	407064
> -1
> -1	99	
> Cell2=24	635	N	control	31318_at	0	13	A	T	A	0	406424
> -1
> -1	99	
> Cell3=631	397	N	control	31318_at	1	13	T	A	T	1	254711
> -1	-1	99	
> 
> 
> 
> [Unit113]
> Name=NONE
> Direction=2
> NumAtoms=16
> NumCells=32
> UnitNumber=113
> UnitType=3
> NumberBlocks=1
> 
> [Unit113_Block1]
> Name=31320_at
> BlockNumber=1
> NumAtoms=16
> NumCells=32
> StartPosition=0
> StopPosition=15
> CellHeader=X	Y	PROBE	FEAT	QUAL	EXPOS	POS	CBASE	PBASE
> TBASE	ATOM	INDEX	CODONIND	CODON	REGIONTYPE	REGION
> Cell1=68	63	N	control	31320_at	0	13	T	A	T	0	40388	-1
> -1	99	
> Cell2=68	64	N	control	31320_at	0	13	T	T	T	0	41028	-1
> -1	99	
> Cell3=99	194	N	control	31320_at	1	13	C	C	C	1	124259
> -1
> -1	99	
> 
> 
> 
> 
> 
> I have a file with identifiers that are found in the
> first file as :
> Name=31320_at
> 
> 
> I am interested in getting lines of block that are
> present in first to be written as a file.  
> 
> I am search:
> 
> search = re.search ["_at")
> 
> 
> my question:
> how can i tell python to select some rows that have
> particular pattern such as [Name] or Name of [Unit].
> 
> is there any way of doing this. 
> please help me
> 
> thanks
> kumar
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

=====
Rick Muller
rick_muller at yahoo.com


		
__________________________________ 
Do you Yahoo!? 
Dress up your holiday email, Hollywood style. Learn more.
http://celebrity.mail.yahoo.com


More information about the Tutor mailing list