絶対パスを取得
Pythonで絶対パスを取得するには,「os.path.abspath」を使う。
os.path — Common pathname manipulations — Python 3.7.3 documentationos.path.abspath(path)
Return a normalized absolutized version of the pathname path. On most platforms, this is equivalent to normpath(join(os.getcwd(), path)).
例:標準入力から取得したファイル名を絶対パスに変換する。
import getopt import os def main(argv): for opt, arg in opts: if opt in ("-i", "--input"): pdb_file, chainid = arg.split(',') pdb_file = os.path.abspath(pdb_file)
なお,入力は次のようになると想定しています。
$ ./example.py -i ./sample/3bji.pdb,A