It is a script to generate a list quickly when you want a list of prefectures in web development.
prefecture
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
FORMAT_DEFAULT = '%s';
DATA = """Hokkaido
Aomori Prefecture
Iwate Prefecture
Miyagi Prefecture
Akita
Yamagata Prefecture
Fukushima Prefecture
Ibaraki Prefecture
Tochigi Prefecture
Gunma Prefecture
Saitama
Chiba
Tokyo
Kanagawa Prefecture
Niigata Prefecture
Toyama Prefecture
Ishikawa Prefecture
Fukui prefecture
Yamanashi Prefecture
Nagano Prefecture
Gifu Prefecture
Shizuoka Prefecture
Aichi prefecture
Mie Prefecture
Shiga Prefecture
Kyoto
Osaka
Hyogo prefecture
Nara Prefecture
Wakayama Prefecture
Tottori prefecture
Shimane Prefecture
Okayama Prefecture
Hiroshima Prefecture
Yamaguchi Prefecture
Tokushima Prefecture
Kagawa Prefecture
Ehime Prefecture
Kochi Prefecture
Fukuoka Prefecture
Saga Prefecture
Nagasaki Prefecture
Kumamoto Prefecture
Oita Prefecture
Miyazaki prefecture
Kagoshima prefecture
Okinawa Prefecture"""
def main():
parser = argparse.ArgumentParser(description='Print prefectures')
parser.add_argument('-f', '--format', metavar="format", type=str, help="line format" , default=FORMAT_DEFAULT)
parser.add_argument('-n', '--no-line-break', help="if add this, print all in one line", action='store_true')
args = parser.parse_args()
lines = []
if args.no_line_break is False:
line_break = "\n"
else:
line_break = ""
for line in DATA.split("\n"):
lines.append(args.format % line)
print line_break.join(lines)
if __name__ == "__main__":
main()
For now, just list:
$ prefecture
Hokkaido
Aomori Prefecture
(Abbreviation)
Kagoshima prefecture
Okinawa Prefecture
Separated by commas:
$ prefecture -f "%s,"
Hokkaido,
Aomori Prefecture,
(Abbreviation)
Kagoshima prefecture,
Okinawa Prefecture,
Separate with commas and put out in one line:
$ prefecture -f "%s," --no-line-break
Hokkaido,Aomori Prefecture,...,Kagoshima prefecture,Okinawa Prefecture,
Enclose in quotes and put out with commas:
$ prefecture -f "'%s',"
'Hokkaido',
'Aomori Prefecture',
(Abbreviation)
'Kagoshima prefecture',
'Okinawa Prefecture',
etc
Recommended Posts