[BangPypers] File operations
Shashidhar Paragonda
shashidhar85 at gmail.com
Wed Oct 19 13:48:03 CEST 2011
Dear Noufal,
Thanks for your reply
I did in this way is it efficient way to achieve the same requirement
all_lines_in_file = open("file.txt", "r").readlines()
>> for line in range(0, len(all_lines_in_file)-1):
>> if "resultsToPDFFile" in all_lines_in_file[line]:
>> if
all_lines_in_file[line].split('->')[1].split(')')[0].split("'")[1].strip()
== 'true':
>> self.cnc_parameters['PDF'] = "ON"
>> elif "resultToExportToPDFDialog" in
all_lines_in_file[line]:
>> if
all_lines_in_file[line+1].split(')')[0].split('#')[1] == 'off':
>> self.cnc_parameters['PDF'] = "OFF"
>> else:
>> self.cnc_parameters['PDF'] = "ASK"
On Wed, Oct 19, 2011 at 3:52 PM, Noufal Ibrahim <noufal at gmail.com> wrote:
> Shashidhar Paragonda <shashidhar85 at gmail.com> 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
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
-----------------------------------
Regards,
Shashidhar N.Paragonda
shashidhar85 at gmail.com
+919449073835
More information about the BangPypers
mailing list