PHPなら構造がシンプルなので、
$methodname = "loadfilter"; $someClass->$methodname( $fff , );
等と書ける。これはPHPの非常に便利なところ。これを使わないとPHPのソースはすっきりしない。ClassをXMLで定義するなんて無茶も出来るし、SimpleXMLモジュールで大活躍する.
同じことをPythonで出来るのだろうか
#BaseHTTPServer.pyのそーすの一部 def handle_one_request(self): """Handle a single HTTP request. You normally don't need to override this method; see the class __doc__ string for information on how to handle specific HTTP commands such as GET and POST. """ self.raw_requestline = self.rfile.readline() if not self.raw_requestline: self.close_connection = 1 return if not self.parse_request(): # An error code has been sent, just exit return mname = 'do_' + self.command if not hasattr(self, mname): self.send_error(501, "Unsupported method (%r)" % self.command) return method = getattr(self, mname) method()
"do_" に注目。 "do_XXXXX"という、メソッドをロードしてる。
オブジェクトのアトリビュートを取り出して、丸かっこで、関数を実行する。なるほど。これが解決法でしょうか。ほかにもあるのかな。