4

Plone Products.PythonScript で変数の型をチェックしようとしています。私はこのコードを試しました:

if isinstance(var, list):
    do(sth)

残念ながら、'list' と 'type' は PythonScript では制限されています。このエラーが発生しました:

 TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

変数の型をチェックする可能性はありますか?

4

3 に答える 3

5

Python スクリプトは、特別な関数を使用して、same_type()型に設定された制限を回避できます。

if same_type(var, []):

listここでは、型自体ではなく、リテラルの空のリスト表記を使用します (型が再割り当てされたため)。

于 2013-11-08T19:10:52.730 に答える
-1

http://developer.plone.org/functionality/expressions.html#python-expressionに基づいて、これはどうですか?あなたはsthのように試すことができます

expression = Expression("if isinstance(var, list): myflag=True")
expression_context = getExprContext(self.context)
value = expression(expression_context) 
于 2013-11-08T18:40:05.370 に答える