Last active
June 16, 2021 22:05
-
-
Save greglinch/6116488 to your computer and use it in GitHub Desktop.
Python script to batch generate files based on a variable. Save this file in a new directory and make the desired modifications. Open terminal and cd into that directory. Type $ python ./file-generator.py to execute the script.
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
values = ['comma','separated', 'list', 'of','values', 'each', 'surrounded', 'by', 'quotes'] | |
# for each item in the list of items | |
for value in values: | |
# construct the filename; prefix or suffix optional | |
filename = 'prefix-' + value + '.jpt' | |
# open the file to be written | |
fo = open(filename, 'w') | |
# write the content in the file including the value being passed to each; %s indicates a string | |
fo.write('%s' % value) | |
# example using an iframe | |
# fo.write('<iframe src="http://www.washingtonpost.com/wp-srv/special/politics/election-map-2012/homepage/embed-map.html?mapstate=%s" width="610" height="502" scrolling="no" frameborder="0"></iframe>' % state) | |
#close the file | |
fo.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment