-1
コードはPython 2.5で実行されますが、この例外は2.6で失敗しますPython 2.6で "keyword argument repeated"例外をキャンセルすることはできますか?
コードはPython 2.5で実行されますが、この例外は2.6で失敗しますPython 2.6で "keyword argument repeated"例外をキャンセルすることはできますか?
例外はソースの構文エラーです。修正する唯一の方法は関数呼び出しを修正することです。
Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(x): pass
...
>>> f(x=1, x=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for keyword argument 'x'
>>> f(x=1, **{'x': 2})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for keyword argument 'x'
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(x): pass
...
>>> f(x=1, x=2)
File "<stdin>", line 1
SyntaxError: keyword argument repeated
>>> f(x=2, **{'x': 1})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for keyword argument 'x'
**何**コード? <><> – SilentGhost
私はそれが解析時間のエラーだと思います。これを行うコードはとにかく壊れています。 – delnan