Skip to content

Commit

Permalink
Use sys.stdout instead of /dev/stdout
Browse files Browse the repository at this point in the history
`/dev/stdout` isn't portable, it isn't available everywhere, e.g. on Haiku.
  • Loading branch information
jmairboeck authored and praiskup committed Aug 26, 2024
1 parent dc2f37c commit ade76cc
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions argparse_manpage/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def write_to_filename(text, filename):
Write given text into a filename at once. Pre-create the parent directory
if it doesn't exist yet. Print to stdout if filename == '-'.
"""
filename = filename if filename != '-' else '/dev/stdout'
dirname = os.path.dirname(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)
with open(filename, 'w') as stream:
stream.write(text)
if filename == '-':
sys.stdout.write(text)
else:
dirname = os.path.dirname(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)
with open(filename, 'w') as stream:
stream.write(text)

0 comments on commit ade76cc

Please sign in to comment.