3
を取得し、私は以下のようにtype_of
方法を探しています:PythonのBSONライブラリ:BSONエイリアス
import bson
bson.type_of(42) # it should return "int".
bson.type_of("hello") # it should return "string".
type("hello").__name__ # it returns "str" and not "string" therefore no suitable.
私は(int
とstring
)欲しい結果は(https://docs.mongodb.com/manual/reference/bson-types/を参照)BSONの別名です。
このメソッドtype_of
は既に存在しますか?
型の数字(Doubleの場合は1、Stringの場合は2 ...)が返されても問題ありません。
は、
編集ありがとう:ここ を一瞬私が持っているソリューションです。
type_of = {
type(2.5).__name__: "number",
type(1).__name__: "number",
type("a_string").__name__: "string",
type([1, 2]).__name__: "array",
type(True).__name__: "bool"
} # type_of[type(3).__name__] returns "number"
ありがとうございました。確かに、このタイプは私が探しているタイプではありません。しかし、私はbsonライブラリから私を助ける方法を探します。 – Matias