خرید بک لینک

Vote count: 0

I've this xml file:

<block>
<key>variable</key>
<param>
  <key>comment</key>
  <value></value>
</param>
<param>
  <key>_enabled</key>
  <value>True</value>
</param>
<param>
  <key>_coordinate</key>
  <value>(8, 235)</value>
</param>
<param>
  <key>_rotation</key>
  <value>0</value>
</param>
<param>
  <key>id</key>
  <value>freq</value>
</param>
<param>
  <key>value</key>
  <value>4.17e9</value>
</param>

I've to modify the attribute of value (value = 4.17e9 i mean).

I've wrote this function to read it :

grc_radio_program_name = kwargs['grc_radio_program_name']
    file_extension = kwargs['file_extension']
    tree = ET.ElementTree(file=os.path.join(os.path.expanduser("~"),"test",grc_radio_program_name+file_extension))
    root = tree.getroot()
    for block in root.findall('block'):
        if block.findtext('key') == 'variable':
            for param in block.findall('param'):
                if param.findtext('key') == 'id' and param.findtext('value') == 'freq':
                    for param in block.findall('param'):
                        if param.findtext('key') == 'value':
                            print(param.findtext('value'))


        if block.findtext('key') == 'variable':
            for param in block.findall('param'):
                if param.findtext('key') == 'id' and param.findtext('value') == 'gain':
                    for param in block.findall('param'):
                        if param.findtext('key') == 'value':
                            #param.text = '10'
                            print(param.findtext('value'))

it works without problem. How can i do something like 'param.findtext('value') = 2.4e9' and then overwrite the original file? thanks

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 15 تير 1395 ساعت: 19:25

صفحه بندی