Created
December 11, 2014 01:48
-
-
Save bruab/a883d09de34d0f2b6935 to your computer and use it in GitHub Desktop.
Writing multiple output files in Python (based on command line argument)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you run
you get "foo.cat" and "foo.dog"