Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
指定された個数のローカル変数定義を含むJavaコードを生成
#!/usr/bin/env python3
# coding: utf-8
import argparse
# 指定された個数のローカル変数の定義を含むJavaコードを生成
CODE_TEMPLATE = '''
package main;
public class Main {{
public static void main(String[] args) {{
{0}
System.out.println("hello, world!");
}}
}}
'''
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-n', type=int, required=True)
parser.add_argument('--out', type=str, required=True)
args = parser.parse_args()
definitions_str = ''
for i in range(args.n):
definitions_str += " int a{};\n".format(i+1)
code = CODE_TEMPLATE.format(definitions_str)
with open(args.out, mode='w') as f:
f.write(code)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment