strings

Here are some extra remarks of how to handle strings:

Python2: 
========

In [1]: type( u'abc')
Out[1]: unicode

In [2]: type( 'abc')
Out[2]: str

socket.send( 'abc')

Python3:
========
#
# strings are always unicode
#
In [12]: type( 'abc')
Out[12]: str
In [13]: type( u'abc')
Out[13]: str

In [14]: text = 'abc'
#
# string (unicode) to bytearray
#   utf-8: variable width character encoding
#          the first 128 characters correspond to ascii
#
In [15]: byteArray = bytearray( text, encoding='utf-8')
         byteArray = 'abc'.encode( 'ascii')

In [16]: str(byteArray)
Out[16]: "bytearray(b'abc')"

In [17]: byteArray
Out[17]: b'abc'

In [18]: byteArray[0]
Out[18]: 97

In [19]: text[0]
Out[19]: 'a'
#
# bytearray to string
#
In [20]: byteArray.decode( "utf-8")
Out[20]: 'abc'
#
# socket.send() sends bytes
#
socket.send( bytearray( 'abc', encoding='utf-8'))