Hi All
Again I am struck with an Issue if the plist file has multiple dictionary in
it then I am not able to get the value of particular key element for
example, In the below plist file I wanted to get the value of stepID &
COMPONENTNAME
key.
I was trying like this
for key in plist:
if 'results' in key:
stepIDValue = key['results']['Steps']['stepID']
I am getting error "string indices must be integers, not str". Please help
me out
PLIST FILE
http://www.test.com/DTDs/PropertyList-1.0.dtd";>
commandStatus
success
comments
Get Test Script
results
Keywords
No keywords.
Steps
activeFlag
0
expectedResult
expectedTime
:00:00
instructions
Launch
stepData
Test APP
stepID
7663365
stepNumber
1
stepPriority
5
summary
title
Launching SDM Application
columns
ACTIVE_FLAG
1
BUSINESS_CATEGORY
CHANGE_MANAGEMENT_ID
COMPONENTNAME
Software Client
COMPREVVERS
Admin
CREATION_DATE
15-Mar-2011 04:52:01
LAST_UPDATE_DATE
15-Mar-2011 06:06:52
PRIORITY
5
REGRESSION
STATUS_ID
1
TEST_LEVEL
TEST_REGION
TEST_SCRIPT_TITLE
Software_Auto
TRACK_NAME
On Tue, Mar 15, 2011 at 11:03 AM, Python User wrote:
> Hi Vinay,
>
> Thanks a Lot it worked for me :)
>
> Thanks Once Again
>
>
> On Tue, Mar 15, 2011 at 1:27 AM, Vinay Shastry wrote:
>
>> On 15 March 2011 01:21, Vinay Shastry wrote:
>> > On 14 March 2011 17:21, Python User 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
>> >>
>> >>
>> >> > >> http://www.test.com/DTDs/PropertyList-1.0.dtd";>
>> >>
>> >>
>> >>
>> >> command
>> >> GetTestScriptData
>> >> comments
>> >> Get Test Script
>> >> opParam
>> >>
>> >> scriptNO
>> >> 12345
>> >> columnNames
>> >> Test case
>> >> fetchKey
>> >> 1
>> >> fetchData
>> >> 1
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> 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
>> ___
>> BangPypers mailing list
>> BangPypers@python.org
>> http://mail.python.org/mailman/listinfo/bangpypers
>>
>
>
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers