Re: Subclassing tuple and introspection

2015-12-02 Thread Joseph L. Casale
> If you're not already familiar with collections.namedtuple, have a > look at it, as it sounds like just naming the fields may be all that > you need. You can also subclass it further to add methods if desired. Yeah, all the types in these collections are named tuples... The collection itself isn

Re: Subclassing tuple and introspection

2015-12-02 Thread Ian Kelly
#x27;re not already familiar with collections.namedtuple, have a look at it, as it sounds like just naming the fields may be all that you need. You can also subclass it further to add methods if desired. > However, if the method returns one element of the collection, how can > one enable introspectio

Subclassing tuple and introspection

2015-12-02 Thread Joseph L. Casale
nable introspection for users of IDE's that the resulting reference is of type A, and therefor has A's fields? For example: col = (Class(..), Class(...)) item = col[0] Introspection will now enumerate item as an instance of Class, providing its fields. The subclass of tuple breaks this. Is there

Re: What does "shell introspection" mean?

2011-06-26 Thread Thomas 'PointedEars' Lahn
Juan Kinunt wrote: > In the PyDev installation documentation you see this sentence: > > "The Forced builtin libs are the libraries that are built-in the > interpreter, such as __builtin__, sha, etc or libraries that should > forcefully analyzed through shell introspection

What does "shell introspection" mean?

2011-06-25 Thread Juan Kinunt
In the PyDev installation documentation you see this sentence: "The Forced builtin libs are the libraries that are built-in the interpreter, such as __builtin__, sha, etc or libraries that should forcefully analyzed through shell introspection (the other option to analyze modules with too

Re: Finding closures through introspection

2010-06-14 Thread John Nagle
On 6/14/2010 9:33 PM, Steven D'Aprano wrote: On Mon, 14 Jun 2010 20:46:28 -0700, John Nagle wrote: So how can I detect a closure? I *think* you do it through the co_flags attribute of the code object. This is in Python 2.5: although this doesn't seem to be documented, at least not here: htt

Re: Finding closures through introspection

2010-06-14 Thread Ian Kelly
On Mon, Jun 14, 2010 at 9:46 PM, John Nagle wrote: > No indication there that "fbar" is a closure inside "foo".  There > are "__closure__" and "__func_closure__" entries in there, but > they are both None.  A non-closure function has the same entries. > > So how can I detect a closure? Maybe beca

Re: Finding closures through introspection

2010-06-14 Thread Steven D'Aprano
On Mon, 14 Jun 2010 20:46:28 -0700, John Nagle wrote: > So how can I detect a closure? I *think* you do it through the co_flags attribute of the code object. This is in Python 2.5: >>> def f(x): ... def g(): ... return x ... return g ... >>> >>> closure = f(42) >>> closure(

Finding closures through introspection

2010-06-14 Thread John Nagle
I'm doing something with CPython introspection, and I'm trying to determine whether a function is a closure. Consider def foo(x) : global fbar def bar(y) : pass fbar = bar # export closure foo(0) We now have "fbar" as a reference to a closure.

Re: Introspection

2010-01-10 Thread m...@infoserv.dk
Thanks Miki and Jason. I knew it could be done :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Introspection

2010-01-06 Thread Jason Scheirer
On Jan 6, 8:38 am, Steven D'Aprano wrote: > On Wed, 06 Jan 2010 06:53:40 -0800, m...@infoserv.dk wrote: > > I'm looking for a way to make a list of string literals in a class. > > > Example: > > > class A: > >    def method(self): > >        print 'A','BC' > > ExtractLiterals(A) > > ['A','BC'

Re: Introspection

2010-01-06 Thread Steven D'Aprano
On Wed, 06 Jan 2010 06:53:40 -0800, m...@infoserv.dk wrote: > I'm looking for a way to make a list of string literals in a class. > > Example: > > class A: >def method(self): >print 'A','BC' > ExtractLiterals(A) > ['A','BC'] > > Is this possible? Can anyone point me in the rig

Re: Introspection

2010-01-06 Thread Miki
Hello Martin, > I'm looking for a way to make a list of string literals in a class. from inspect import getsourcelines from tokenize import generate_tokens, STRING, NUMBER def is_literal(t): return t[0] in (STRING, NUMBER) def get_lieterals(obj): lines, _ = getsourcelines(obj) readli

Introspection

2010-01-06 Thread m...@infoserv.dk
I'm looking for a way to make a list of string literals in a class. Example: class A: def method(self): print 'A','BC' >>> ExtractLiterals(A) ['A','BC'] Is this possible? Can anyone point me in the right direction? Thanks. /Martin -- http://mail.python.org/mailman/listinfo/python-l

Re: feedback on function introspection in argparse

2009-11-14 Thread Chris Withers
Yuv wrote: On Nov 8, 1:33 am, Carl Banks wrote: Is the docstring expected to be formatted according to some convention? We tried to comply to PEP 257 and we're open to suggestions on this. I'd suggest at the very least supporting Sphinx docstrings that have the parameters in them... Chri

Re: feedback on function introspection in argparse

2009-11-07 Thread Carl Banks
On Nov 7, 3:44 pm, Yuv wrote: > On Nov 8, 1:33 am, Carl Banks wrote: > > > Is the docstring expected to be formatted according to some > > convention? [snippage] > We tried to comply to PEP 257 and we're open to suggestions on this. Ah, so we finally get to the answer: the convention is PEP 2

Re: feedback on function introspection in argparse

2009-11-07 Thread Yuv
On Nov 8, 1:33 am, Carl Banks wrote: > Is the docstring expected to be formatted according to some > convention? Yes it does, we parse the docstring as explained in argparse.py: def _parse_docstring(function): """Parses a function's docstring for a description of the function and for help

Re: feedback on function introspection in argparse

2009-11-07 Thread Carl Banks
On Nov 7, 2:45 pm, Yuv wrote: > This was posted to the argparse mailing list by Steven Bethard and now > we'd like some feedback from comp.lang.python. > > We now have a branch[5] of argparse that supports an ``argparse.run`` > function[6] which does > some function i

Re: feedback on function introspection in argparse

2009-11-07 Thread geremy condra
On Sat, Nov 7, 2009 at 5:45 PM, Yuv wrote: > This was posted to the argparse mailing list by Steven Bethard and now > we'd like some feedback from comp.lang.python. > > We now have a branch[5] of argparse that supports an ``argparse.run`` > function[6] which does > some fu

feedback on function introspection in argparse

2009-11-07 Thread Yuv
This was posted to the argparse mailing list by Steven Bethard and now we'd like some feedback from comp.lang.python. We now have a branch[5] of argparse that supports an ``argparse.run`` function[6] which does some function introspection to build a command line parser from a function defin

Re: introspection question: get return type

2009-05-15 Thread Aahz
In article <4a0d2e07$0$9422$426a7...@news.free.fr>, Bruno Desthuilliers wrote: >Aahz a écrit : >> In article <4a0c6e42$0$12031$426a7...@news.free.fr>, >> Bruno Desthuilliers wrote: >>> Marco Mariani a écrit : Bruno Desthuilliers wrote: > Oh, you meant the "return type" ? Nope, no way.

Re: introspection question: get return type

2009-05-15 Thread Bruno Desthuilliers
Aahz a écrit : In article <4a0c6e42$0$12031$426a7...@news.free.fr>, Bruno Desthuilliers wrote: Marco Mariani a écrit : Bruno Desthuilliers wrote: Oh, you meant the "return type" ? Nope, no way. It just doesn't make sense given Python's dynamic typing. Unless he's really trying to write in N

Re: introspection question: get return type

2009-05-14 Thread George Sakkis
On May 14, 3:55 pm, a...@pythoncraft.com (Aahz) wrote: > In article <4a0c6e42$0$12031$426a7...@news.free.fr>, > Bruno Desthuilliers   wrote: > > >Marco Mariani a écrit : > >> Bruno Desthuilliers wrote: > > >>> Oh, you meant the "return type" ? Nope, no way. It just doesn't make > >>> sense given Py

Re: introspection question: get return type

2009-05-14 Thread Terry Reedy
Aahz wrote: In article <4a0c6e42$0$12031$426a7...@news.free.fr>, Bruno Desthuilliers wrote: Marco Mariani a �crit : Bruno Desthuilliers wrote: Oh, you meant the "return type" ? Nope, no way. It just doesn't make sense given Python's dynamic typing. Unless he's really trying to write in Noht

Re: introspection question: get return type

2009-05-14 Thread Aahz
In article <4a0c6e42$0$12031$426a7...@news.free.fr>, Bruno Desthuilliers wrote: >Marco Mariani a écrit : >> Bruno Desthuilliers wrote: >>> >>> Oh, you meant the "return type" ? Nope, no way. It just doesn't make >>> sense given Python's dynamic typing. >> >> Unless he's really trying to write i

Re: introspection question: get return type

2009-05-14 Thread Bruno Desthuilliers
Marco Mariani a écrit : Bruno Desthuilliers wrote: Oh, you meant the "return type" ? Nope, no way. It just doesn't make sense given Python's dynamic typing. I thought that the OP was writing a tool to document not-very-dynamic code. Unless he's really trying to write in Nohtyp, You mean

Re: introspection question: get return type

2009-05-14 Thread Marco Mariani
Bruno Desthuilliers wrote: Oh, you meant the "return type" ? Nope, no way. It just doesn't make sense given Python's dynamic typing. I thought that the OP was writing a tool to document not-very-dynamic code. Unless he's really trying to write in Nohtyp, the language where value types are mo

Re: introspection question: get return type

2009-05-14 Thread bearophileHUGS
On the other hand, generally good programming practice suggests you to write functions that have a constant return type. And in most programs most functions are like this. This is why ShedSkin can indeed infer the return type of functions in "good behaved" programs. To do this ShedSkin uses a quite

Re: introspection question: get return type

2009-05-14 Thread Bruno Desthuilliers
execution time !-) using introspection? something like this, suppose I want to know the type of the return value for the method "getsomething". Is it possible to get it without actually calling 'getsomething'? Oh, you meant the "return type" ? Nope, no way. It

Re: introspection question: get return type

2009-05-14 Thread Diez B. Roggisch
Diez B. Roggisch wrote: > flam...@gmail.com wrote: > >> Hello, >> I am wondering if it's possible to get the return value of a method >> *without* calling it using introspection? > > Nope. All that's possible to see if there is a implicit or explicit r

Re: introspection question: get return type

2009-05-14 Thread bearophileHUGS
flam...@gmail.com: > I am wondering if it's possible to get the return value of a method > *without* calling it using introspection? Python is dynamically typed, so you can create a function like this: >>> foo = lambda x: "x" if x else 1 >>> foo(1) &

Re: introspection question: get return type

2009-05-14 Thread Diez B. Roggisch
flam...@gmail.com wrote: > Hello, > I am wondering if it's possible to get the return value of a method > *without* calling it using introspection? Nope. All that's possible to see if there is a implicit or explicit return through dis.disassemble - if you find "LOAD_CONST

introspection question: get return type

2009-05-14 Thread flamz3d
Hello, I am wondering if it's possible to get the return value of a method *without* calling it using introspection? something like this, suppose I want to know the type of the return value for the method "getsomething". Is it possible to get it without actually calling 

Re: Python introspection and namespace weird question

2008-12-01 Thread Chris Rebert
On Mon, Dec 1, 2008 at 12:23 PM, Rayene Ben Rayana <[EMAIL PROTECTED]> wrote: > Thanks Chris, > > Yeah it is kinda meta thing. My app allows to create a scene (a set of GUI > objects). A scene can be saved as a python script. And, it can be loaded > again using execfile(). > > each GUI object has a

Re: Python introspection and namespace weird question

2008-12-01 Thread Rayene Ben Rayana
Thanks Chris, Yeah it is kinda meta thing. My app allows to create a scene (a set of GUI objects). A scene can be saved as a python script. And, it can be loaded again using execfile(). each GUI object has a label. So, in the script scene, declaring an object in a scene file should look like this

Re: Python introspection and namespace weird question

2008-12-01 Thread Chris Rebert
On Mon, Dec 1, 2008 at 6:04 AM, Rayene Ben Rayana <[EMAIL PROTECTED]> wrote: > Hello everybody, > > Is there an easy way to do something like this in python ? > red_car = MyVehicleClass() car = red_car car.labels() > ['red_car' , 'car' ] > > In other words, does an instance has acces

Python introspection and namespace weird question

2008-12-01 Thread Rayene Ben Rayana
Hello everybody, Is there an easy way to do something like this in python ? >>> red_car = MyVehicleClass() >>> car = red_car >>> car.labels() ['red_car' , 'car' ] In other words, does an instance has access to its name pointers ? Thanks in advance, Rayene -- http://mail.python.org/mailman/list

Re: class / module introspection?

2008-04-02 Thread Brian Munroe
On Apr 2, 2:26 pm, 7stud <[EMAIL PROTECTED]> wrote: > > You don't need that helper function, which is a little tricky to > follow: > Well, I appreciate the code sharing you did, but the helper function is nice and compact, and I didn't have much trouble following it. I ended up doing the followi

Re: class / module introspection?

2008-04-02 Thread [EMAIL PROTECTED]
On 2 avr, 22:04, Brian Munroe <[EMAIL PROTECTED]> wrote: > On Apr 2, 12:33 pm, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > > > Why not do the import here, so you store a real module instead of a > > name ? > > Right now I'm still in the prototyping phase and haven't really > thought everyt

Re: class / module introspection?

2008-04-02 Thread 7stud
On Apr 2, 1:27 pm, Brian Munroe <[EMAIL PROTECTED]> wrote: > On Apr 2, 12:07 pm, Brian Munroe <[EMAIL PROTECTED]> wrote: > > > > > This gives me ['system1','system2'] - which I can then use __import__ > > on. > > Addendum, thanks Bruno! > > I also required the helper function (my_import) from the P

Re: class / module introspection?

2008-04-02 Thread Brian Munroe
On Apr 2, 12:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > Why not do the import here, so you store a real module instead of a > name ? > Right now I'm still in the prototyping phase and haven't really thought everything through. I needed the names because I am populating a GUI sele

Re: class / module introspection?

2008-04-02 Thread [EMAIL PROTECTED]
On 2 avr, 21:07, Brian Munroe <[EMAIL PROTECTED]> wrote: > On Apr 2, 11:04 am, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > > > More seriously: the answer is in the > > doc.http://www.python.org/doc/2.3.5/lib/built-in-funcs.html > > > read about the __import__ function, experiment in your

Re: class / module introspection?

2008-04-02 Thread Brian Munroe
On Apr 2, 12:07 pm, Brian Munroe <[EMAIL PROTECTED]> wrote: > > This gives me ['system1','system2'] - which I can then use __import__ > on. > Addendum, thanks Bruno! I also required the helper function (my_import) from the Python docs you pointed me to, that actually was the key to getting every

Re: class / module introspection?

2008-04-02 Thread Brian Munroe
On Apr 2, 11:04 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > More seriously: the answer is in the > doc.http://www.python.org/doc/2.3.5/lib/built-in-funcs.html > > read about the __import__ function, experiment in your interactive > python shell, and you should be done in a couple minut

Re: class / module introspection?

2008-04-02 Thread [EMAIL PROTECTED]
> be1 = system1.Backend() > be1.getStatus() > > This would work great if I knew about system1 and system2 ahead of > time, but that isn't the case. Having to rewrite main.py every time a > new backend module comes along is obviously a stupid idea too. I've > been think

class / module introspection?

2008-04-02 Thread Brian Munroe
y time a new backend module comes along is obviously a stupid idea too. I've been thinking I need some kind of introspection, but I've been reading about it and a whole mess of design pattern stuff, so my head is swimming and I am totally unsure of what the best approach is. My guess

Re: introspection question

2008-01-07 Thread Peter Otten
Alex K wrote: Please don't top-post. > On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote: >> Alex K wrote: >> >> > What would be the simplest way of enumerating all methods and members >> > (including inherited) of a given object? Thank you. >> >> inspect.getmembers() > Nice thank you. But an

Re: introspection question

2008-01-07 Thread Guilherme Polo
2008/1/7, Alex K <[EMAIL PROTECTED]>: > Nice thank you. But anyway to make it look pretty? > pprint.pprint(inspect.getmembers(someobject)) > On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote: > > Alex K wrote: > > > > > What would be the simplest way of enumerating all methods and members > >

Re: introspection question

2008-01-07 Thread Alex K
Nice thank you. But anyway to make it look pretty? On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote: > Alex K wrote: > > > What would be the simplest way of enumerating all methods and members > > (including inherited) of a given object? Thank you. > > inspect.getmembers() > > Peter > -- > htt

Re: introspection question

2008-01-07 Thread Peter Otten
Alex K wrote: > What would be the simplest way of enumerating all methods and members > (including inherited) of a given object? Thank you. inspect.getmembers() Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: introspection question

2008-01-07 Thread Guilherme Polo
2008/1/7, Alex K <[EMAIL PROTECTED]>: > Hi Guys, > > What would be the simplest way of enumerating all methods and members > (including inherited) of a given object? Thank you. > > Alex > -- > http://mail.python.org/mailman/listinfo/python-list > import inspect inspect.getmembers(yourobject) --

introspection question

2008-01-07 Thread Alex K
Hi Guys, What would be the simplest way of enumerating all methods and members (including inherited) of a given object? Thank you. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: introspection and functions

2007-08-23 Thread Wildemar Wildenburger
Ricardo Aráoz wrote: > Ayaz Ahmed Khan wrote: > >> "James Stroud" typed: >> >>> py> def doit(a, b, c, x=14): >>> ... pass >>> ... >>> py> doit.func_code.co_argcount >>> 4 >>> py> doit.func_code.co_varnames >>> ('a', 'b', 'c', 'x') >>> py> doit.func_defaults >>> (14,) >>> >> Neat. >

Re: introspection and functions

2007-08-23 Thread Ricardo Aráoz
Ayaz Ahmed Khan wrote: > "James Stroud" typed: >> py> def doit(a, b, c, x=14): >> ... pass >> ... >> py> doit.func_code.co_argcount >> 4 >> py> doit.func_code.co_varnames >> ('a', 'b', 'c', 'x') >> py> doit.func_defaults >> (14,) > > Neat. > How do you know the 14 corresponds to x ? -- http

Re: introspection and functions

2007-08-22 Thread Ayaz Ahmed Khan
"James Stroud" typed: > py> def doit(a, b, c, x=14): > ... pass > ... > py> doit.func_code.co_argcount > 4 > py> doit.func_code.co_varnames > ('a', 'b', 'c', 'x') > py> doit.func_defaults > (14,) Neat. -- Ayaz Ahmed Khan I have not yet begun to byte! -- http://mail.python.org/mailman/listinf

Re: introspection and functions

2007-08-22 Thread Scott David Daniels
yagyala wrote: > Hi. I would like to be able to tell, at run time, how many parameters > a function requires. Ideally I would like to be able to tell which are > optional as well. I've tried looking at the functions attributes, but > haven't found one that helps in this. How can I do this? > > Tha

Re: introspection and functions

2007-08-22 Thread Bruno Desthuilliers
yagyala a écrit : > Hi. I would like to be able to tell, at run time, how many parameters > a function requires. Ideally I would like to be able to tell which are > optional as well. I've tried looking at the functions attributes, but > haven't found one that helps in this. How can I do this? >>>

Re: introspection and functions

2007-08-22 Thread James Stroud
yagyala wrote: > Hi. I would like to be able to tell, at run time, how many parameters > a function requires. Ideally I would like to be able to tell which are > optional as well. I've tried looking at the functions attributes, but > haven't found one that helps in this. How can I do this? > > Tha

Re: introspection and functions

2007-08-22 Thread Wildemar Wildenburger
yagyala wrote: > Hi. I would like to be able to tell, at run time, how many parameters > a function requires. Ideally I would like to be able to tell which are > optional as well. I've tried looking at the functions attributes, but > haven't found one that helps in this. How can I do this? > I'v

introspection and functions

2007-08-22 Thread yagyala
Hi. I would like to be able to tell, at run time, how many parameters a function requires. Ideally I would like to be able to tell which are optional as well. I've tried looking at the functions attributes, but haven't found one that helps in this. How can I do this? Thanks -- http://mail.python

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-25 Thread Aahz
In article <[EMAIL PROTECTED]>, Alex Martelli <[EMAIL PROTECTED]> wrote: >Aahz <[EMAIL PROTECTED]> wrote: >>Alex: >>> >>>But don't put such black magic in production. The completely different >>>way is: just don't. >> >> Could you expand on that? After all, that's exactly what we do to >> implem

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Alex Martelli
Martin Drautzburg <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > > Yes, there is: use an ORM to do the SQL generation for you. Check out > > SQLAlchemy, it will buy you much more than what you asked for. > > Might look, though in general I don't like OR mappers much. Having SQL > generate

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Alex Martelli
Aahz <[EMAIL PROTECTED]> wrote: > >But don't put such black magic in production. The completely different > >way is: just don't. > > Could you expand on that? After all, that's exactly what we do to > implement a super() that works with classic classes -- and it's certainly > production code.

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Aahz
In article <[EMAIL PROTECTED]>, Alex Martelli <[EMAIL PROTECTED]> wrote: >Martin Drautzburg <[EMAIL PROTECTED]> wrote: >> >> The problem is the first part: how can I lookup the callers module and >> the classobjs defined in there? Or finding any constant strings in the >> caller's module would also

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Martin Drautzburg
Peter Otten wrote: def SQL(sql): > ...     print sql > ... a = SQL("module") > module # that one was obvious class A: > ...     b = SQL("class") > ...     def method(self, c=SQL("default arg")): > ...             d = SQL("method") > ... You are my hero. Indeed very cool! -- http:/

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Martin Drautzburg
George Sakkis wrote: > Yes, there is: use an ORM to do the SQL generation for you. Check out > SQLAlchemy, it will buy you much more than what you asked for. Might look, though in general I don't like OR mappers much. Having SQL generated feels as strange as having python code generated. Too much

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Peter Otten
Martin Drautzburg wrote: > > def SQL(sql, checked=set()): > > if sql in checked: > > return True > > if not valid_sql(sql): raise ValueError > > checked.add(sql) > > return sql > > No this does not do the trick. I will not be able to validate an sql > statement bofore I ru

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Alex Martelli
Martin Drautzburg <[EMAIL PROTECTED]> wrote: ... > The problem is the first part: how can I lookup the callers module and > the classobjs defined in there? Or finding any constant strings in the > caller's module would also be just fine. Or is there a completely > different way to do such a thin

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread George Sakkis
On Apr 21, 4:16 pm, Martin Drautzburg <[EMAIL PROTECTED]> wrote: > I would like to validate sql strings, which are spread all over the > code, i.e. I run ("prepare") them against a database to see if it happy > with the statements. Spelling errors in sql have been a major pain for > me. > > The sta

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Scott David Daniels
Martin Drautzburg wrote: > I would like to validate sql strings, which are spread all over the > code, The statements will not be assembled from smaller pieces, > but they will not neccessarily be defined at module level. I could > live with class level, > parse the source file, but I am

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Martin Drautzburg
Peter Otten wrote: > Martin Drautzburg wrote: > >> I would like to validate sql strings, which are spread all over the >> code, i.e. I run ("prepare") them against a database to see if it >> happy with the statements. Spelling errors in sql have been a major >> pain for me. > > def validateSQL(

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Peter Otten
Martin Drautzburg wrote: > I would like to validate sql strings, which are spread all over the > code, i.e. I run ("prepare") them against a database to see if it happy > with the statements. Spelling errors in sql have been a major pain for > me. > > The statements will not be assembled from sma

Namespaces/introspection: collecting sql strings for validation

2007-04-21 Thread Martin Drautzburg
I would like to validate sql strings, which are spread all over the code, i.e. I run ("prepare") them against a database to see if it happy with the statements. Spelling errors in sql have been a major pain for me. The statements will not be assembled from smaller pieces, but they will not neccess

Re: How much introspection is implementation dependent?

2007-02-03 Thread James Stroud
George Sakkis wrote: > On Feb 2, 6:56 pm, James Stroud <[EMAIL PROTECTED]> wrote: > >> Hello, >> >> I wanted to automagically generate an instance of a class from a >> dictionary--which might be generated from yaml or json. I came up with this: >> >> (snip) >> >> == >> >> #! /usr/bin/env python >>

Re: How much introspection is implementation dependent?

2007-02-03 Thread James Stroud
George Sakkis wrote: > On Feb 2, 6:56 pm, James Stroud <[EMAIL PROTECTED]> wrote: > >> Hello, >> >> I wanted to automagically generate an instance of a class from a >> dictionary--which might be generated from yaml or json. I came up with this: >> >> (snip) >> >> == >> >> #! /usr/bin/env python >>

Re: How much introspection is implementation dependent?

2007-02-02 Thread George Sakkis
On Feb 2, 6:56 pm, James Stroud <[EMAIL PROTECTED]> wrote: > Hello, > > I wanted to automagically generate an instance of a class from a > dictionary--which might be generated from yaml or json. I came up with this: > > (snip) > > == > > #! /usr/bin/env python > > # automagical constructor > def c

How much introspection is implementation dependent?

2007-02-02 Thread James Stroud
.im_func.func_code.co_varnames argnames = vnames[1:-len(dflts)] argvals = [adict.pop(n) for n in argnames] return cls(*argvals, **adict) I'm wondering, I did a lot of introspection here. How much of this introspection can I count on in other implementations. Is this a byproduct of CPython? Will all cl

Re: Dynamic/runtime code introspection/compilation

2006-11-28 Thread Thomas W
Great !!! That works like charm. Thanks alot. Thomas Leo Kislov wrote: > Thomas W wrote: > > Maybe a stupid subject, but this is what I want to do : > > > > I got some python code stored in a string: > > > > somecode = """ > > > > from somemodule import ISomeInterface > > > > class Foo(ISomeIn

Re: Dynamic/runtime code introspection/compilation

2006-11-28 Thread Leo Kislov
Thomas W wrote: > Maybe a stupid subject, but this is what I want to do : > > I got some python code stored in a string: > > somecode = """ > > from somemodule import ISomeInterface > > class Foo(ISomeInterface): > param1 = ... > param2 = > > """ > > and I want to compile that code so

Re: Dynamic/runtime code introspection/compilation

2006-11-28 Thread Fredrik Lundh
Thomas W wrote: > from somemodule import ISomeInteface > > d = compile(sourcecode) > > myfoo = d.Foo() > > print ISomeInterface in myfoo.__bases__ > > Any hints? Python is a dynamic language, so compiling something won't tell you much about what the code actually does. the only reliable way

Dynamic/runtime code introspection/compilation

2006-11-28 Thread Thomas W
Maybe a stupid subject, but this is what I want to do : I got some python code stored in a string: somecode = """ from somemodule import ISomeInterface class Foo(ISomeInterface): param1 = ... param2 = """ and I want to compile that code so that I can use the Foo-class and check w

Re: introspection

2006-09-01 Thread rick
Fredrik Lundh wrote: > brad tilley wrote: > >> How do I import a module and then ask it to show me its methods or >> other aspects about itself during execution? I'd like to do something >> such as this: >> >> import win32api > > dir(win32api) > help(win32api) > > and also > > import inspect

Re: introspection

2006-08-31 Thread Fredrik Lundh
brad tilley wrote: > How do I import a module and then ask it to show me its methods or other > aspects about itself during execution? I'd like to do something such as > this: > > import win32api dir(win32api) help(win32api) and also import inspect help(inspect) -- http://mail.python.org

Re: introspection

2006-08-31 Thread Ben Finney
brad tilley <[EMAIL PROTECTED]> writes: > How do I import a module and then ask it to show me its methods or other > aspects about itself during execution? I'd like to do something such as > this: > > import win32api > > print win32api.methods() > > I'd like to write some test scripts that load

Re: introspection

2006-08-31 Thread John Machin
brad tilley wrote: > How do I import a module and then ask it to show me its methods or other > aspects about itself during execution? I'd like to do something such as > this: > > import win32api > > print win32api.methods() > > I'd like to write some test scripts that load modules and probe them

introspection

2006-08-31 Thread brad tilley
How do I import a module and then ask it to show me its methods or other aspects about itself during execution? I'd like to do something such as this: import win32api print win32api.methods() I'd like to write some test scripts that load modules and probe them for information about themselves

Re: Help in using introspection to simplify repetitive code

2006-08-27 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > As you mention, wether the methods take arguments or not is something > to have into account. > And they do take arguments, and a variable number of them, so AFAIK > hooking with __getattr__ or __getattribute__ will not work, as you can > only get the method name with

Re: Help in using introspection to simplify repetitive code

2006-08-21 Thread Tim N. van der Leeuw
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > And they do take arguments, and a variable number of them, so AFAIK > > hooking with __getattr__ or __getattribute__ will not work, as you can > > only get the method name with that. > > why not just return the bound method *object* (a callable

Re: Help in using introspection to simplify repetitive code

2006-08-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > And they do take arguments, and a variable number of them, so AFAIK > hooking with __getattr__ or __getattribute__ will not work, as you can > only get the method name with that. why not just return the bound method *object* (a callable), and let the caller call that a

Re: Help in using introspection to simplify repetitive code

2006-08-21 Thread [EMAIL PROTECTED]
As you mention, wether the methods take arguments or not is something to have into account. And they do take arguments, and a variable number of them, so AFAIK hooking with __getattr__ or __getattribute__ will not work, as you can only get the method name with that. I was thinking of some __call__

Re: Help in using introspection to simplify repetitive code

2006-08-20 Thread Terry Reedy
legation.) > The handler object is the same in all methods. > > I was wondering if there is a way to simplify this proxy class, maybe > using some pythonic technique like metaclasses, introspection... any > suggestion is appreciated. My immediate thought would be to start with _forw

Re: Help in using introspection to simplify repetitive code

2006-08-20 Thread Simon Percivall
dName(self): > self._handlerClass.thisIsTheMethodName() > > The handler object is the same in all methods. > > I was wondering if there is a way to simplify this proxy class, maybe > using some pythonic technique like metaclasses, introspection... any > suggestion is appreciated. > &g

Help in using introspection to simplify repetitive code

2006-08-20 Thread [EMAIL PROTECTED]
ndler object is the same in all methods. I was wondering if there is a way to simplify this proxy class, maybe using some pythonic technique like metaclasses, introspection... any suggestion is appreciated. Thanks, Javier Sanz -- http://mail.python.org/mailman/listinfo/python-list

SOAP/WSDL Introspection

2006-08-01 Thread Ben Edwards (lists)
I have the below code to get info about SOAP services at a wsdl url. It gets the in parameters OK but does not seem to get out/return parameters. Any idea why? Ben from SOAPpy import WSDL import sys wsdlfile = "http://www.xmethods.net/sd/2001/TemperatureService.wsdl"; server = WSDL.Proxy(wsdl

Re: Introspection Class/Instance Name

2006-04-26 Thread robert
*binarystar* wrote: > Hello there, > > what method would you use to return the name of the class and/or > instance introspectively eg. > > class Bollocks: > > def __init__( self ): > > print self.__method_that_returns_class_name__() > print self.__method_that_ret

Re: Introspection Class/Instance Name

2006-04-26 Thread Duncan Booth
ce_of_bollocks >>> print another_name.name_of_instance() ??? which name should appear here ??? >>> more = [another_name]*5 >>> print more[2] ??? and what name here ??? and did you want a global name, or a local variable from some function and if so which function and at wh

Re: Introspection Class/Instance Name

2006-04-26 Thread [EMAIL PROTECTED]
What about: py> class A: py. def __init__(self): py. print self.__class__.__name__ py. print str(self) py. def __str__(self): py. return 'instance of %s' % self.__class__.__name__ py. py> a = A() A instance of A py> -- http://mail.python.org/mailman/l

Re: Introspection Class/Instance Name

2006-04-25 Thread Roland Heiber
*binarystar* wrote: > Hello there, > > what method would you use to return the name of the class and/or > instance introspectively eg. > > class Bollocks: > > def __init__( self ): > > print self.__method_that_returns_class_name__() > print self.__method_that_ret

Introspection Class/Instance Name

2006-04-25 Thread *binarystar*
Hello there, what method would you use to return the name of the class and/or instance introspectively eg. class Bollocks: def __init__( self ): print self.__method_that_returns_class_name__() print self.__method_that_returns_inst

Re: Graphical introspection utilities?

2006-02-04 Thread Ravi Teja
Oops. http://www.activestate.com/_images/screenshots/ss_Komodo_rails_large.gif is the debugger screenshot for Ruby (Komodo supports more than one language). Python's debugger in Komodo looks exactly the same. -- http://mail.python.org/mailman/listinfo/python-list

  1   2   >