[BangPypers] plist files
vinayshastry at gmail.com
Mon Mar 14 20:57:02 CET 2011
On 15 March 2011 01:21, Vinay Shastry <vinayshastry at gmail.com> wrote:
> On 14 March 2011 17:21, Python User <python.user.01 at gmail.com> wrote:
>> Hi All,
>> I have a plist file, test.plist, All I want is read the scriptNO tag value
>> 12345 and replace it with 67899. Can any one please help me out for
>> this. The file content is
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE plist PUBLIC "-//test//EN" "
>> <plist version="1.0">
>> <string>Get Test Script</string>
>> <string>Test case</string>
>> I was using the below code to read the plist file, but I am not able to
>> search the scriptNo and replace it with other value.
>> import plistlib
>> file = ('/Users/me/Desktop/test.plist')
>> plist = plistlib.readPlist(file)
>> print plist
>> Please help me out to solve this. Thanks In Advance.
> The answer is in your plist format itself. Everything is enclosed in
> an array - which becomes a list in py.
> How about something like this:
> for key in plist:
> if 'opParam' in key and 'scriptNO' in key['opParam']:
> key['opParam']['scriptNO'] = 67899
> plistlib.writePlist(plist, "mynewfile.plist")
> Also, is there a reason why file is a tuple containing filename, and
> not just a string?
Oh, and your DTD is wrong.
Vinay S Shastry
More information about the BangPypers