Script (Python)

Zope の Script (Python) で、パラメタリストを渡す方法にいろいろ悩みました。第一に、Edit タブ の Parameter List に

name="noname", age

とか書くと、name のデフォルト引数すらちゃんと取ってくれない現象に悩みました。これは私のミスで、Python 関数のデフォルト引数と同じでデフォルト付き引数の後には無デフォルト引数リストは置けないのでした。(これは、Python Reference Manual の 7.5 節で次のように説明されています。

If a parameter has a default value, all following parameters must also have a default value -- this is a syntactic restriction that is not expressed by the grammar.

理由は良く分かりません。誰か教えて。)
次に、コード中に

##Parameters=name="noname", age

とか書いてもちゃんと認識されなかったのですが、これはコード中の最初の部分に置かないとダメなんですかね。正しくコードの先頭行に置くと、セーブしたときに、この「##」部分が消されて、必要な Parameter List のフォームに移動され記録されるみたいです。マニュアルによると以下の通りです。やっぱり、先頭じゃないとダメなんですね。

Files uploaded into a Script (Python) instance may either consist only of the actual body of the function, or the file containing the function body may contain at its head a set of lines starting with "##" which describe bindings, parameters, and the title.

><