Python 2.6.1 : expected path separator ([)

前端 未结 1 1929
失恋的感觉
失恋的感觉 2021-02-19 20:12

I am getting a path separator error in python 2.6.1. I have not found this issue with python 2.7.2 version, but unfortunately I need this in 2.6.1 only. Is there any another way

相关标签:
1条回答
  • 2021-02-19 20:45

    You are using an XPath expression, that is not supported by the ElementTree version included in Python 2.6. You'll need to filter for the attribute manually, after a .findall():

    def final_xml(self,username):
        users = self.root.findall("user")
        for user in users:
            if user.attrib.get('username') == 'user1':
                break
        else:
            raise ValueError('No such user')
    
        # `user` is now set to the correct element
        self.root.remove(user)
        print user
        tree = ET.ElementTree(self.root)
        tree.write("msl.xml") 
    
    0 讨论(0)
提交回复
热议问题