You're right, that works. In fact everything works now, the same code
that did't work yesterday and don't have a clue what's happening.
Thank you for your replies and sorry about the kind of false thread I
started.
> Are you sure you encoded your unicode object to a str before trying to
> serialize it?
> It seems like cStringIO is working fine for me, until the last command, where
> I try
> to write a unicode object directly into it.
>
> In [1]: from cStringIO import StringIO
>
> In [2]: buf = StringIO()
>
> In [3]: my_uni = u'\u03a9'
>
> In [4]: my_uni
> Out[4]: u'\u03a9'
>
> In [5]: len(my_uni)
> Out[5]: 1
>
> In [6]: my_bin = my_uni.encode('utf-8')
>
> In [7]: my_bin
> Out[7]: '\xce\xa9'
>
> In [8]: len(my_bin)
> Out[8]: 2
>
> In [9]: buf.write(my_bin)
>
> In [10]: buf.getvalue()
> Out[10]: '\xce\xa9'
>
> In [11]: buf.getvalue().decode('utf8')
> Out[11]: u'\u03a9'
>
> In [12]: buf.getvalue().decode('utf8') == my_uni
> Out[12]: True
>
> In [13]: buf.write(my_uni)