Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
six ライブラリにはタプル型定義がないようで、現在、Python 2 と Python 3 の両方で動作する方法で以下のコードを記述しようとしています。
return (type(key) in (types.TupleType, types.ListType)
PS。その行について私を責めないでください、私はそれを移植しようとしているだけで、私が書いたものではありません;)
最良の方法は次のとおりです。
return isinstance(key, (tuple, list))
これは単純で、直接的で、明確で、2.x と 3.x の両方で機能し、サブクラスを適切に処理します。