Skip to content

Instantly share code, notes, and snippets.

@bruab
Created December 11, 2014 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruab/a883d09de34d0f2b6935 to your computer and use it in GitHub Desktop.
Save bruab/a883d09de34d0f2b6935 to your computer and use it in GitHub Desktop.
Writing multiple output files in Python (based on command line argument)
#!/usr/bin/env python
import sys
if len(sys.argv) < 2:
sys.stderr.write("usage: write_two_files.py <filename prefix>\n")
sys.exit()
prefix = sys.argv[1]
first_filename = prefix + ".dog"
with open(first_filename, 'w') as first:
first.write("woof woof\n")
second_filename = prefix + ".cat"
with open(second_filename, 'w') as second:
second.write("hiss hiss <pees on floor>\n")
@bruab
Copy link
Author

bruab commented Dec 11, 2014

if you run

python write_two_files.py foo

you get "foo.cat" and "foo.dog"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment