"Yubin Ruan" wrote in message news:47f3acf9-8da2-4aad-a6f0-7a9efbdfe...@googlegroups.com...

In my understanding, writing to a file would requires that everything be written byte by byte. So writing objects of type 'bytes' to socket makes sense. But, how could python write to file using unicode(type 'str')? Does python encode 'str'(Unicode) automatically before writing things to file? If it's true, then why can't it do that automatic encoding when I trying to write a 'str' to socket ?


If you open a file for writing in text mode, using 'w', it expects a string.

If you open it in binary mode, using 'wb', it expects bytes.

HTH

Frank Millman


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to