introspection

SQLAlchemy introspect column type with inheritance

删除回忆录丶 提交于 2020-01-22 17:30:07
问题 Considering this code (and using SQLAlchemy 0.7.7): class Document(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')) __mapper_args__ = {'polymorphic_on': type_document} class Arrete(Document): __tablename__ = 'arrete' __table_args__ = { 'schema': 'app' } __mapper

Find functions explicitly defined in a module (python)

﹥>﹥吖頭↗ 提交于 2020-01-20 02:15:01
问题 Ok I know you can use the dir() method to list everything in a module, but is there any way to see only the functions that are defined in that module? For example, assume my module looks like this: from datetime import date, datetime def test(): return "This is a real method" Even if i use inspect() to filter out the builtins, I'm still left with anything that was imported. E.g I'll see: ['date', 'datetime', 'test'] Is there any way to exclude imports? Or another way to find out what's

Find functions explicitly defined in a module (python)

两盒软妹~` 提交于 2020-01-20 02:13:04
问题 Ok I know you can use the dir() method to list everything in a module, but is there any way to see only the functions that are defined in that module? For example, assume my module looks like this: from datetime import date, datetime def test(): return "This is a real method" Even if i use inspect() to filter out the builtins, I'm still left with anything that was imported. E.g I'll see: ['date', 'datetime', 'test'] Is there any way to exclude imports? Or another way to find out what's

getting the C python exec argument string or accessing the evaluation stack

ε祈祈猫儿з 提交于 2020-01-13 06:34:49
问题 In my python debugger I have a way of remapping a string to a filename so that when you are stepping through an exec'd function inside the debugger you can list lines pygmentized, or view them along inside an editor like Emacs via realgud. So I'd like to be able to extract the string in an exec statement when CPython is stopped inside evaluating that. I already have a mechanism that can look back in the call frame to see if the caller was an EXEC_STMT and I can look back one instruction to

Introspecting arguments from the constructor function __init__ in Python

做~自己de王妃 提交于 2020-01-12 23:43:50
问题 What is a way to extract arguments from __init__ without creating new instance. The code example: class Super: def __init__(self, name): self.name = name I am looking something like Super.__dict__.keys() type solution. Just to retrieve name argument information without adding any values. Is there such an option to do that? 回答1: You can use inspect >>> import inspect >>> inspect.getargspec(Super.__init__) ArgSpec(args=['self', 'name'], varargs=None, keywords=None, defaults=None) >>> Edit:

AS3 knowing how many arguments a function takes

五迷三道 提交于 2020-01-11 06:10:28
问题 Is there a way to know how many arguments an instance of Function can take in Flash? It would also be very useful to know if these arguments are optional or not. For example : public function foo() : void //would have 0 arguments public function bar(arg1 : Boolean, arg2 : int) : void //would have 2 arguments public function jad(arg1 : Boolean, arg2 : int = 0) : void //would have 2 arguments with 1 being optional Thanks 回答1: Yes there is: use the Function.length property. I just checked the

Can Python determine the class of an object accessing a method

倾然丶 夕夏残阳落幕 提交于 2020-01-09 11:22:38
问题 Is there anyway to do something like this: class A: def foo(self): if isinstance(caller, B): print "B can't call methods in A" else: print "Foobar" class B: def foo(self, ref): ref.foo() class C: def foo(self, ref): ref.foo() a = A(); B().foo(a) # Outputs "B can't call methods in A" C().foo(a) # Outputs "Foobar" Where caller in A uses some form of introspection to determine the class of the calling method's object? EDIT : In the end, I put this together based on some of the suggestions:

Can Python determine the class of an object accessing a method

邮差的信 提交于 2020-01-09 11:22:05
问题 Is there anyway to do something like this: class A: def foo(self): if isinstance(caller, B): print "B can't call methods in A" else: print "Foobar" class B: def foo(self, ref): ref.foo() class C: def foo(self, ref): ref.foo() a = A(); B().foo(a) # Outputs "B can't call methods in A" C().foo(a) # Outputs "Foobar" Where caller in A uses some form of introspection to determine the class of the calling method's object? EDIT : In the end, I put this together based on some of the suggestions:

How to introspectively connect handlers to signals?

天涯浪子 提交于 2020-01-04 04:39:08
问题 gtk.Builder is capable to identify all signals that a GUI (described in a XML file) can emit and with the method connect_signals() automagically matches signals and handlers. Example: class Gui(gobject.GObject): def __init__(self): self.gui_file = "../data/gui.xml" builder = gtk.Builder() builder.add_from_file(self.gui_file) builder.connect_signals(self) def on_whatever_gui_event(self, widget, data=None): ... In my application I have other signals that are generated by non-GUI objects (it's

Finding out which functions are available from a class instance in python?

白昼怎懂夜的黑 提交于 2020-01-01 19:06:09
问题 How do you dynamically find out which functions have been defined from an instance of a class? For example: class A(object): def methodA(self, intA=1): pass def methodB(self, strB): pass a = A() Ideally I want to find out that the instance 'a' has methodA and methodB, and which arguments they take? 回答1: Have a look at the inspect module. >>> import inspect >>> inspect.getmembers(a) [('__class__', <class '__main__.A'>), ('__delattr__', <method-wrapper '__delattr__' of A object at 0xb77d48ac>),