lundi 29 juin 2015

Re-open a file in binary mode with Python


Say I have a file object which was opened in mode 'r' (such as from the default open() call), but I need to read it in binary mode ('rb').

Is there a way to change the mode directly, or do I need to make a new file object using something like open(foo.name, 'rb') (assuming my file object is named foo)?

EDIT: Ideally, the solution to this problem should be platform-independent.


Aucun commentaire:

Enregistrer un commentaire