Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Need help!!!! Problem doing this bit of code
QtWS25 Last Chance

Need help!!!! Problem doing this bit of code

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 3 Posters 255 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    darealmash
    wrote on last edited by
    #1

    import xml.etree.ElementTree as ET

    data = ('''
    <person>
    <name>Chuck</name>
    <phone type = "intl">
    +1 734 303 4456
    </phone>
    <email hide+"yes"/>
    </person>''')

    tree = ET.fromstring(data)
    print('Name:', tree.find('name').text)
    print('Attr:', tree.find('email').get('hide'))

    i keep on getting this traceback: line 12, in <module>
    tree = ET.fromstring(data)
    and also get tracebac for the xml file elementtree:
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\xml\etree\ElementTree.py", line 1347, in XML
    parser.feed(text)
    xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 7, column 21

    JonBJ 1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @darealmash said in Need help!!!! Problem doing this bit of code:

      <email hide+"yes"/>

      <email hide="yes"/>

      1 Reply Last reply
      2
      • D darealmash

        import xml.etree.ElementTree as ET

        data = ('''
        <person>
        <name>Chuck</name>
        <phone type = "intl">
        +1 734 303 4456
        </phone>
        <email hide+"yes"/>
        </person>''')

        tree = ET.fromstring(data)
        print('Name:', tree.find('name').text)
        print('Attr:', tree.find('email').get('hide'))

        i keep on getting this traceback: line 12, in <module>
        tree = ET.fromstring(data)
        and also get tracebac for the xml file elementtree:
        File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\xml\etree\ElementTree.py", line 1347, in XML
        parser.feed(text)
        xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 7, column 21

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @darealmash said in Need help!!!! Problem doing this bit of code:

        xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 7, column 21

        As @JoeCFD has said, did you try looking at line 7, column 21?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved