草庐IT

introspect

全部标签

python - 声明类的 SQLAlchemy 自省(introspection)

我正在编写一个小的sqlalchemyshim以通过一些轻量级数据转换从MySQL数据库中导出数据——主要是更改字段名称。我当前的脚本工作正常,但需要我基本上描述我的模型两次——一次在类声明中,一次作为要迭代的字段名称列表。我正在尝试弄清楚如何使用内省(introspection)来识别作为列访问器的行对象的属性。以下工作几乎完美:forattr,valueinself.__class__.__dict__.iteritems():ifisinstance(value,sqlalchemy.orm.attributes.InstrumentedAttribute):self.__cla

Python 自省(introspection) : description of the parameters a function takes

是否有一个类似于dir()的模块工具可以告诉我给定函数需要哪些参数?例如,我想做一些像dir(os.rename)这样的事情,让它告诉我记录了哪些参数,这样我就可以避免在线检查文档,而是只使用Python脚本接口(interface)做这个。 最佳答案 我知道您对help(thing)或thing.__doc__更感兴趣,但是如果您尝试进行程序化自省(introspection)(而不是人类-可读文档)来了解调用函数,然后你可以使用inspectmodule,如thisquestion中所讨论.

python - 对 pygtk3 的自省(introspection)可能吗?

python的一大优点是能够对方法和函数进行自省(introspection)。例如,要获取math.log的函数签名,您可以(在ipython中)运行此命令:In[1]:math.log?Type:builtin_function_or_methodBaseClass:StringForm:Namespace:InteractiveDocstring:log(x[,base])Returnthelogarithmofxtothegivenbase.Ifthebasenotspecified,returnsthenaturallogarithm(basee)ofx.并且看到x和可选的b

python - 通过内省(introspection)查找位置参数的名称

有没有办法找出python函数的位置参数的名称?deffoo(arg1,arg2):passf=foo#HowdoIfindoutwantthe1stargumenttofiscalled?Iwant'arg1'asananswer 最佳答案 函数inspect.getargspec()在Python2中做你需要的。在Python3中,这已被弃用,您应该改为使用signature. 关于python-通过内省(introspection)查找位置参数的名称,我们在StackOverflo

python - 通过自省(introspection)打印 ctypes "Structure"的所有字段

测试.c:#include#includestructs{chara;intb;floatc;doubled;};structs*create_struct(){structs*res=malloc(sizeof(structs));res->a=1;res->b=2;res->c=3.0f;res->d=4.0;returnres;}测试.py:fromctypesimport*classS(Structure):_fields_=[('a',c_byte),('b',c_int),('c',c_float),('d',c_double)]lib=CDLL('./test.so')c

python - 具有继承性的 SQLAlchemy 自省(introspection)列类型

考虑这段代码(并使用SQLAlchemy0.7.7):classDocument(Base):__tablename__='document'__table_args__={'schema':'app'}id=Column(types.Integer,primary_key=True)nom=Column(types.Unicode(256),nullable=False)date=Column(types.Date())type_document=Column(types.Enum('arrete','photographie',name='TYPES_DOCUMENT_ENUM')

Caused by: java.lang.IllegalStateException: Failed to introspect Class

1、问题报错如下:Causedby:java.lang.IllegalStateException:FailedtointrospectClass[com.jeequan.jeepay.components.mq.vender.rabbitmq.RabbitMQBeanProcessor]fromClassLoader[sun.misc.Launcher$AppClassLoader@18b4aac2]2、问题解析:意思是:未能反射rabbitmq类包(就是添加了依赖没加载进去);需与ClassNotFindException的错误区分,此异常是引用了没有依赖的类。3、解决方案:方案一(如果导

python - 内省(introspection)调用对象

我如何从b.func()内省(introspection)A的实例(即A的实例的self):classA():defgo(self):b=B()b.func()classB():deffunc(self):#IntrospecttofindthecallingAinstancehere 最佳答案 通常我们不希望func能够访问A的调用实例,因为这会破坏encapsulation.在b.func中,您应该可以访问传递的任何args和kwargs,实例b的状态/属性(通过self此处),以及周围的任何全局变量。如果你想知道一个调用对象,

python - pytest 在辅助函数中断言自省(introspection)

pytest做的很棒assertintrospection所以很容易找到字符串中的差异,尤其是当差异在空白处时。现在我使用一个稍微复杂的测试助手,我在许多测试用例中重复使用它。助手也有自己的模块,我想为该模块添加断言内省(introspection)。helpers.py:...defmy_helper():assert'abcy'=='abcx'test_mycase.py:from.helpersimportmy_helperdeftest_assert_in_tc():assert'abcy'=='abcx'deftest_assert_in_helper():my_helper

python - pytest 在辅助函数中断言自省(introspection)

pytest做的很棒assertintrospection所以很容易找到字符串中的差异,尤其是当差异在空白处时。现在我使用一个稍微复杂的测试助手,我在许多测试用例中重复使用它。助手也有自己的模块,我想为该模块添加断言内省(introspection)。helpers.py:...defmy_helper():assert'abcy'=='abcx'test_mycase.py:from.helpersimportmy_helperdeftest_assert_in_tc():assert'abcy'=='abcx'deftest_assert_in_helper():my_helper