KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In Python 2.x with 'file-like' object: sys.stdout.write(bytes_) tempfile.TemporaryFile().write(bytes_) open('filename', 'wb').write(bytes_) StringIO().write(bytes_) How can I do the same in Python 3? How can I write equivalent of the following Python 2.x code? def write(file_, bytes_): file_.write(bytes_) Note: sys.stdout is not always semantically a text stream. It might be beneficial to consider it as a stream of bytes sometimes. For example, make encrypted archive of dir/ on remote machine : tar -c dir/ | gzip | gpg -c | ssh user@remote 'dd of=dir.tar.gz.gpg' There is no point to use Unicode in this case.
Tags (comma-separated)
Save Edits
Cancel