xml string is enclosed with b'<xml_string>' while generating from dictionary using dicttoxml module
Question: I am using [dicttoxml](https://pypi.python.org/pypi/dicttoxml) module for
converting dictionary into 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' }}
                  }        
    
    from 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 do not know why it is enclosed with b' '. How to generate xml string without
this b''?

Browser is also giving error msg when opening xml file with this content.


Answer: That is the normal represenation of a String that is not Unicode in Python 3.
Try this in the 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 only contain ASCII literal characters.
    

So everything is OK. You don't have a problem.

See also [`str`](https://docs.python.org/3/library/stdtypes.html#text-
sequence-type-str) vs
[`bytes`](https://docs.python.org/3/library/stdtypes.html#binary-sequence-
types-bytes-bytearray-memoryview).

**Edit:**

See how encoding and 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 just use `my_byte_string.decode(my_encoding)` where `my_encoding` is
probably `"UTF-8"`.

