io.open vs. codecs.open

Albert-Jan Roskam fomcl at yahoo.com
Wed Mar 4 07:12:17 EST 2015


Hi,

Is there a (use case) difference between codecs.open and io.open? What is the difference?
A small difference that I just discovered is that codecs.open(somefile).read() returns a bytestring if no encoding is specified*), but a unicode string if an encoding is specified. io.open always returns a unicode string.

*) I had never tried that before. I would have expected that encoding would default to e.g locale.getpreferredencoding().


Thank you!

Regards,

Albert-Jan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a 

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Python-list mailing list