Hello Noufal I have tried your solution but i get invalid syntax for this line *with open(............) *I am using python 2.3.5 what could be the problem.
On Wed, Oct 19, 2011 at 3:52 PM, Noufal Ibrahim <[email protected]> wrote: > Shashidhar Paragonda <[email protected]> writes: > > > Dear Python hackers, > > > > I have a text file and the contents are like : > > > > #( > > #resultToExportToCurveDistDialog ' ->' > > #off) > > > > like same structure many lines exists. > > My requirement is I want to find line where > > "resultToExportCurveDistDialog" and other pattern exist. After that I > need > > to fetch the value of it. in above example value > > for "resultToExportCurveDistDialog" is "off" how to move file > > pointer to next line and fetch value as soon as i find my required > patterns. > > Thank you in advance for the help. > > Something like this? Untested. > > keywords = set(["resultToExportToCurveDistDialog", > "resultToExportCurveDistDialog2"...]) > > with open("file.txt", r) as f: > for line in f: > keyword = line.strip("#").split()[0].strip() > if keyword in keywords: > value = f.next() > print "%s : %s"%(keyword, value) > > > -- > ~noufal > http://nibrahim.net.in > > A verbal contract isn't worth the paper it's written on. Include me out. > -Samuel Goldwyn > _______________________________________________ > BangPypers mailing list > [email protected] > http://mail.python.org/mailman/listinfo/bangpypers > -- ----------------------------------- Regards, Shashidhar N.Paragonda [email protected] +919449073835 _______________________________________________ BangPypers mailing list [email protected] http://mail.python.org/mailman/listinfo/bangpypers
