Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #5933
| From | Matthias Urlichs <matthias@urlichs.de> |
|---|---|
| Newsgroups | de.comp.lang.python |
| Subject | [Python-de] raw stdio unter Windows? |
| Date | 2022-12-16 19:16 +0100 |
| Message-ID | <78774179-7e09-93ba-842e-d1065e68fa9a@urlichs.de> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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
Back to de.comp.lang.python | Previous | Next — Next in thread | Find similar
[Python-de] raw stdio unter Windows? Matthias Urlichs <matthias@urlichs.de> - 2022-12-16 19:16 +0100 [Python-de] Re: raw stdio unter Windows? Christopher Arndt <chris@chrisarndt.de> - 2022-12-16 20:49 +0100
csiph-web