1

私は 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」を追加することはできません。1 つの .py ファイルを使用するだけでこれを解決できますが、ソース ファイルが非常に大きくなります。

私は PyMOL メーリング リストで誰も興味を持っていませんでした。そうでない場合、コードを分割するより良い方法はありますか? 私は C++ のヘッダー ファイルに甘んじることに慣れており、Python プロジェクトのアーキテクチャを適切に処理するのは少し難しいです。

編集: さまざまなケースで、このように複数のファイルとダミーのコンパイル クラスで複数の継承を使用することは、複雑な方法で Python プロジェクトを構築するための良い方法ですか?

4

1 に答える 1

1

私が質問を正しく理解していれば、それif __name__ == '__main__'が目的です。

于 2013-03-04T21:53:07.493 に答える