Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. Traceback (most recent call last):
  2. File "./xml.py", line 13, in <module>
  3. fn.text = values
  4. File "src/lxml/etree.pyx", line 1018, in lxml.etree._Element.text.__set__
  5. File "src/lxml/apihelpers.pxi", line 710, in lxml.etree._setNodeText
  6. File "src/lxml/apihelpers.pxi", line 698, in lxml.etree._createTextNode
  7. File "src/lxml/apihelpers.pxi", line 1491, in lxml.etree._utf8
  8. TypeError: Argument must be bytes or unicode, got 'list'
  9.  
  10. values = base64.b64encode(values)
  11.  
  12. Traceback (most recent call last):
  13. File "./xml.py", line 10, in <module>
  14. values = base64.b64encode(values)
  15. File "/usr/lib/python2.7/base64.py", line 54, in b64encode
  16. encoded = binascii.b2a_base64(s)[:-1]
  17. TypeError: b2a_base64() argument 1 must be string or buffer, not list
  18.  
  19. <FileName>['1235362363151512d12d']</FileName>
  20.  
  21. <FileName>1235362363151512d12d</FileName>
  22.  
  23. #!/usr/bin/python
  24.  
  25. from lxml import etree as ET
  26. root = ET.Element("alphanumeric")
  27. file = open("alphanumeric.txt", "r")
  28.  
  29. for aline in file:
  30. values = aline.split()
  31. length = len(values)
  32. child = ET.SubElement(root,"child")
  33.  
  34. fn = ET.SubElement(child, "FileName")
  35. fn.text = values
  36. tree = ET.ElementTree(root)
  37. tree.write("filename.xml")
  38.  
  39. x = ET.parse("filename.xml")
  40. print ET.tostring(x, pretty_print=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement