[Python-de] raw stdio unter Windows?

Matthias Urlichs über python-de <[email protected]> Fri, 16 Dec 2022 19:16:33 +0100
Newsgroups gmane.comp.python.general.german
Message-ID <[email protected]>
Kurze Frage, weil ich keine Windowskiste habe und schon gar nicht mit 
Python drauf:

Funktioniert dieser Code (und produziert eine 4 Bytes lange Datei, wenn 
man die Ausgabe in eine solche umleitet) unter Windows?


import sys

from contextlib import contextmanager

@contextmanager
def maybe_open(filename, mode):
     if filename is None:
         if mode[-1] == "b":
             yield sys.stdin.buffer.raw if mode[0] == "r" else sys.stdout.buffer.raw
         else:
             yield sys.stdin if mode == "r" else sys.stdout
     else:
         with open(filename, mode) as f:
             yield f

with maybe_open(None,"wb") as f:
     f.write(b"ABC\x0A")

-- 
-- mit freundlichen Grüßen
-- 
-- Matthias Urlichs

_______________________________________________
python-de Mailingliste -- [email protected]
Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an [email protected]
https://mail.python.org/mailman3/lists/python-de.python.org/
Mitgliedsadresse: [email protected]
OpenPGP_signature (application/pgp-signature, 840 B) - not displayed