0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python > def main(argv=None): > 引数を無視する?

Last updated at Posted at 2016-10-29
動作環境
Ubuntu 14.04 LTS desktop amd64
GeForce GTX 750 Ti
ASRock Z170M Pro4S [Intel Z170chipset]
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v7.5
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.

TensorFlowというDeep Learningのフレームワークを学習中。

TensorFlowを遊び倒す! 4-1. Convolutional Neural Networks
http://blog.brainpad.co.jp/entry/2016/04/22/170000

CIFAR-10のデータセットを処理するTutorialを読んでいる。

これまで読んできたpythonコードは主に以下のものだった。

mnist_with_summaries.py
def main(_):
  if tf.gfile.Exists(FLAGS.summaries_dir):
    tf.gfile.DeleteRecursively(FLAGS.summaries_dir)
  tf.gfile.MakeDirs(FLAGS.summaries_dir)
  train()

cifar10_train.pyのmain()の定義は以下になっている。

cifar10_train.py
...
def main(argv=None):  # pylint: disable=unused-argument
  cifar10.maybe_download_and_extract()
  if tf.gfile.Exists(FLAGS.train_dir):
    tf.gfile.DeleteRecursively(FLAGS.train_dir)
  tf.gfile.MakeDirs(FLAGS.train_dir)
  train()
...

main()の定義においてargv=Noneという記載ができるようだ。

関連 http://www.artima.com/weblogs/viewpost.jsp?thread=4829

First, we change main() to take an optional 'argv' argument, which allows us to call it from the interactive Python prompt:

def main(argv=None):
    if argv is None:
        argv = sys.argv
    # etc., replacing sys.argv with argv in the getopt() call.

Note that we fill in the default for argv dynamically. This is more flexible than writing

def main(argv=sys.argv):
    # etc.
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?