11
10

More than 5 years have passed since last update.

Python 3:sys.pathとos.pathについて(機械学習,手書き数字認識)

Last updated at Posted at 2018-01-16

sys.pathos.pathとは?

機械学習の手書き数字認識という問題で,データセットを呼び出すときに遭遇.
  • sys.pathの中身はリスト
    • モジュールを検索するパスを示す文字列のリスト
    • 起動時に初期化された後,リストの先頭(path[0])にはPythonインタプリタを起動したスクリプトのあるディレクトリが挿入される
  • os.pathはモジュールで,中身はパス名を操作する関数などが入っている

sys.pathos.pathで何ができるのか?

  • sys.path.argv():Pythonスクリプトに渡されたコマンドライン引数のリスト

    • argv[0]はスクリプトの名前となる
  • sys.path.append()sys.pathに引数内のパスを加える操作を行う

    • sys.path.append(os.pardir)os.pardirは親ディレクトリを表す文字列定数
    • これは,親ディレクトリのファイルをインポートするための設定
  • os.path.join():引数の複数の値をつなげてパスにする関数

まとめ:

  1. システムパラメータや関数をいじるときにsysosモジュールを用いる
  2. データセットの呼び出しという今回の目的に限れば,sys.path.append(os.pardir)の意味するところは,「システムに親ディレクトリまでのパスを加える」といったところか.
11
10
0

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
11
10