我正在使用PyMOL分子浏览器作为更大程序的一个子集,并且为了便于阅读,我打破了我的文件,如下所示...
### command1ClassFile.py
class command1Class():
def command1(self):
print "do action 1, this requires pymol functions"
### command2ClassFile.py
class command2Class():
def command2(self):
print "do action 2, this also requires pymol functions"
### mainModule.py
import command1ClassFile, command2ClassFile
class commandsClass(command1Class, command2Class):
pass
class guiClass(parentClass, commandsClass):
def onLeftClick(self):
self.command1()
def onRightClick(self):
self.command2()
# this imports the module as well as launching the program, unfortunately
import pymol
pymol.finish_launching()我不能只在其他文件的开头添加“import pymol”,因为这会多次启动程序。我可以通过使用一个.py文件来解决这个问题,但是这会导致源文件过大。
我没有在PyMOL邮件列表中发现任何人的兴趣,所以我希望有其他解决方法。如果没有,是否有更好的方法来分解代码?我习惯于被C++中的头文件所迷惑,而且Python项目的体系结构对我来说正确处理有点困难。
编辑:对于不同的情况下,使用跨文件和伪编译类的多重继承以这种方式来构建具有复杂方法的python项目的好方法?