python - xml string is enclosed with b'<xml_string>' while generating from dictionary using dicttoxml module -


i using dicttoxml module converting dictionary xml.

code:

cfg_dict = { 'mobile' :                 { 'checkbox_os' :                   { 'status' : 'none',                      'radiobutton_andriod' :                       { 'status' : 'none',                         'combobox_andriod_brands' : 'lg'},                     'radiobutton_windows' :                       { 'status' : 'none',                         'combobox_windows_brands' : 'nokia'},                     'radiobutton_others' :                       { 'status' : 'none',                         'combobox_others_brands' : 'apple'}},                   'checkbox_screen_size' :                     { 'status' : 'none',                       'doublespinbox_screen_size' : '5.0' }}               }          dicttoxml import dicttoxml xml = dicttoxml(self.cfg_dict) print (xml) 

output:

b'<?xml version="1.0" encoding="utf-8" ?><root><mobile type="dict"><checkbox_os type="dict"><radiobutton_andriod type="dict"><status type="bool">false</status><combobox_andriod_brands type="str">sony</combobox_andriod_brands></radiobutton_andriod><radiobutton_windows type="dict"><status type="bool">false</status><combobox_windows_brands type="str">htc</combobox_windows_brands></radiobutton_windows><status type="bool">false</status><radiobutton_others type="dict"><status type="bool">false</status><combobox_others_brands type="str">apple</combobox_others_brands></radiobutton_others></checkbox_os><checkbox_screen_size type="dict"><doublespinbox_screen_size type="float">5.0</doublespinbox_screen_size><status type="bool">false</status></checkbox_screen_size></mobile></root>' 

i not know why enclosed b' '. how generate xml string without b''?

browser giving error msg when opening xml file content.

that normal represenation of string not unicode in python 3. try in python shell:

>>> type("foo") <class 'str'> >>> type(b"foo") <class 'bytes'> >>> type("rübe") <class 'str'> >>> type(b"rübe")   file "<stdin>", line 1 syntaxerror: bytes can contain ascii literal characters. 

so ok. don't have problem.

see str vs bytes.

edit:

see how encoding , decoding works.

>>> s = "rübe" >>> e = s.encode("utf-8") >>> print(e) b'r\xc3\xbcbe' >>> type(e) <class 'bytes'> >>> d = e.decode("utf-8") >>> d 'rübe' 

so use my_byte_string.decode(my_encoding) my_encoding "utf-8".


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -