Drkcore

26 08 2009 Python Tweet

pythonでコマンドを探す

whichみたいなの、というか、外部プログラムを起動したいときに/usr/local/binにあるのか/opt/local/binにあったりするのだけどいちいち意識しなくていいようにスクリプト中で探したい。

例えばgaston

>>> filter(lambda f: os.path.isfile(f),[os.path.join(d,'gaston') for d in os.environ['PATH'].split(':')])
['/opt/local/bin/gaston', '/opt/local/bin/gaston']

最初にヒットしたものだけ

>>> filter(lambda f: os.path.isfile(f),[os.path.join(d,'gaston') for d in os.environ['PATH'].split(':')])[0]
'/opt/local/bin/gaston'

もっとうまいやりかたあるんだと思うんだけどわからんかった。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021