【发布时间】:2022-01-16 11:55:43
【问题描述】:
我正在寻找一个模块 ifcopenshell,我看到一个非常奇怪的功能:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import functools
import numbers
import itertools
from . import ifcopenshell_wrapper
try:
import logging
except ImportError as e:
logging = type('logger', (object,), {'exception': staticmethod(lambda s: print(s))})
class entity_instance(object):
def __init__(self, e):
if isinstance(e, tuple):
e = ifcopenshell_wrapper.new_IfcBaseClass(*e)
super(entity_instance, self).__setattr__('wrapped_data', e)
在这种情况下,tuple 没有在任何地方显式定义,但它包含一个值。我的假设是 tuple 来自进口。那正确吗?如何追踪tuple 的来源?
这里是函数isininstance的注释:
定义:isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]], /) -> bool 返回对象是类的实例还是其子类的实例。 一个元组,如 isinstance(x, (A, B, ...)),可以作为检查的目标。这相当于 isinstance(x, A) 或 isinstance(x, B) 或 ... 等。
【问题讨论】:
-
我不知道你的问题是什么。你在问什么元组?
-
tuple是内置的,如print或int。它默认在所有模块中可用。 -
未定义的元组如何包含信息?
-
@defladamouse 我正在告诉 isinstance 函数的元组
-
@Brian 但是 isinstance 函数会比较 e 和 tuple,e 是否包含在 tuple 中。默认元组为空。那么函数 isinstance 永远不会被使用?