Only call function if PyMOL running

跟風遠走 提交于 2019-12-08 19:05:29

I'm not an expert on PyMOL (haven't ever scripted it) but I see 2 possible ways:

  1. Do something trivial that requires an open PyMOL session and catch exceptions
  2. Look at process names (something like os.system("ps ux | grep -i pymol"))

First way is better, second is a dirty hack.

I usually just do something like:

try:
    import pymol
    pymol_imported = True
except:
    pymol_imported = False

Then

if pymol_imported:
    display_results(...)

I don't know if that's Python "best practices", but PyMol scripts are usually just quick, one-off things in most cases, anyways.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!