<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
<BR>Hi, Travis,<BR>
 <BR>
Thanks very much for your help. Since each day, my mail box is flooded with python forum email. I simply overlooked your email, eventhough I am desperately waiting for the help. Today when I googled the topic and found your reply.<BR>
 <BR>
I am sorry that I send a similar help request to the forum today.<BR>
 <BR>
Frank<BR><BR>
<BLOCKQUOTE>
<HR>
Date: Tue, 23 Oct 2007 10:08:28 -0400<BR>From: travis.brady@gmail.com<BR>To: python-list@python.org<BR>Subject: Re: parsing the output from matlab<BR><BR><BR>
<DIV><SPAN class=EC_gmail_quote>On 10/22/07, <B class=EC_gmail_sendername>wang frank</B> <<A href="mailto:fw3@hotmail.co.jp">fw3@hotmail.co.jp</A>> wrote</SPAN> 
<BLOCKQUOTE class=EC_gmail_quote style="PADDING-LEFT: 1ex; MARGIN-LEFT: 0.8ex; BORDER-LEFT: #ccc 1px solid">
<DIV> <BR>I have a big log file generated from matlabe, for each variable, it print the name of the variable and an empty line and then the value. such as:<BR> <BR>x1 =<BR> <BR>    0.1<BR> <BR>y =<BR> <BR>   7<BR> <BR>z = <BR> <BR>   6.7<BR> <BR>x1 =<BR> <BR>   0.5<BR> <BR>I want to use python to parse the file and selectively print out the vairable and its value. For example, I want to print out all the value related with x1, so the output will be<BR> <BR>x1 = 0.1<BR>x1 = 0.5.<BR> </DIV></BLOCKQUOTE></DIV>
<DIV><BR class=EC_webkit-block-placeholder></DIV>Here is a fairly naive version with re named groups that should handle the example you pasted. 
<DIV><BR class=EC_webkit-block-placeholder></DIV>
<DIV>
<DIV>
<DIV>In [62]: import re</DIV>
<DIV><BR class=EC_webkit-block-placeholder></DIV>
<DIV>In [63]: px = re.compile('(?P<variable>\w+)\s=\s+(?P<value>\d.*\d*)')</DIV>
<DIV><BR class=EC_webkit-block-placeholder></DIV>
<DIV>In [64]: for var in px.finditer(s):</DIV>
<DIV>    print "%s = %s" %(var.group('variable'), var.group('value'))</DIV>
<DIV>   ....:     </DIV>
<DIV>   ....:     </DIV>
<DIV>a = 0.1</DIV>
<DIV>y = 7</DIV>
<DIV>z = 6.7</DIV>
<DIV>x1 = 0.5</DIV></DIV>
<DIV><BR class=EC_webkit-block-placeholder></DIV>
<DIV>To filter for only the x1's just test for the group named 'variable':</DIV>
<DIV><BR class=EC_webkit-block-placeholder></DIV>
<DIV>
<DIV>In [66]: for var in px.finditer(s):</DIV>
<DIV>   ....:     if var.group('variable')=='x1':</DIV>
<DIV>   ....:         print "%s = %s" %(var.group('variable'), var.group('value')) </DIV>
<DIV>   ....:         </DIV>
<DIV>   ....:         </DIV>
<DIV>x1 = 0.5</DIV></DIV>
<DIV><BR class=EC_webkit-block-placeholder></DIV>
<DIV>But I'm betting these files get more complex than just the snippet you included, in which case it's probably worth looking at pyparsing  <A href="http://pyparsing.wikispaces.com/" target=_blank>http://pyparsing.wikispaces.com/</A> and regular expressions.</DIV></DIV>
<DIV>
<DIV><BR class=EC_webkit-block-placeholder></DIV>
<DIV><BR> </DIV>
<DIV><BR>-- <BR>Travis Brady<BR><A href="http://travisbrady.com/" target=_blank>http://travisbrady.com/</A> </DIV></DIV></BLOCKQUOTE><br /><hr />$B9-9pI=<($J$7!*%"%+%&%s%HM-8z4|8B$J$7!*(BHotmail Plus $B$N$*?=$79~$_$O$3$A$i(B <a href='http://clk.atdmt.com/GBL/go/msnjpqjl0040000011gbl/direct/01/' target='_new'>http://get.live.com/mail/options</a></body>
</html>