from absl import app
from absl import flags
FLAGS = flags.FLAGS
flags.DEFINE_string("name", None, "Your name.")
flags.DEFINE_integer("num_times", 1,
"Number of times to print greeting.")
# Required flag.
flags.mark_flag_as_required("name")
def main(argv):
del argv # Unused.
for i in range(0, FLAGS.num_times):
print('Hello, %s!' % FLAGS.name)
if __name__ == '__main__':
app.run(main)
django 등에서 봤던 프로그래밍 방식을 지원하는 라이브러리로 보인다.
매개변수나 필수 항목, 기본 값, USAGE 출력 등을 미리 처리해주기 때문에 기본적인 스크립트를 작성할 때 간단한 코드로 귀찮은 작업들을 대신해준다.
from absl import app
from absl import flags
from absl import logging
FLAGS = flags.FLAGS
flags.DEFINE_string("name", None, "Your name.")
flags.DEFINE_integer("num_times", 1,
"Number of times to print greeting.")
# Required flag.
flags.mark_flag_as_required("name")
def main(argv):
del argv # Unused.
for i in range(0, FLAGS.num_times):
print('Hello, %s!' % FLAGS.name)
logging.info("test %s" % FLAGS.name)
logging.info('Interesting Stuff')
logging.info('Interesting Stuff with Arguments: %d', 42)
logging.set_verbosity(logging.INFO)
logging.log(logging.DEBUG, 'This will *not* be printed')
logging.set_verbosity(logging.DEBUG)
logging.log(logging.DEBUG, 'This will be printed')
logging.warning('Worrying Stuff')
logging.error('Alarming Stuff')
logging.fatal('AAAAHHHHH!!!!') # Process exits
if __name__ == '__main__':
app.run(main)