Luca wrote:
Yes, this helps a lot. In facts I need to do something like a language parser.
a *parser* that works on object structures created by executing a Python
program?
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, Sep 1, 2008 at 2:18 PM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
>
> If your aim is to write something like a debugger, profiler, or some
> other application that needs to inspect arbitrary objects and work out
> what they do, then you probably should be using:
>
> isinstance(obj.methodNa
On Mon, 01 Sep 2008 11:45:36 +0200, Luca asked about recognizing methods:
> What is the best way to do this? The "most pythonic"?
That depends on why you are doing it, and what you want to do with the
information once you've found it.
If you are experimenting in the interactive interpreter, the
Luca wrote:
On Mon, Sep 1, 2008 at 11:35 AM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
...
But not so easy to fool a type check:
type(x) == new.function
False
Of course that's not bullet-proof either. I leave it as an exercise to
discover how you might break that piece of code.
Ok, so..
On Mon, 01 Sep 2008 11:45:36 +0200, Luca wrote:
>> But not so easy to fool a type check:
>>
> type(x) == new.function
>> False
>>
>> Of course that's not bullet-proof either. I leave it as an exercise to
>> discover how you might break that piece of code.
>>
>>
> Ok, so...
>
> What is the bes
On Mon, Sep 1, 2008 at 11:35 AM, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> That's relatively fragile, since such names aren't reserved in any way.
> It's easy to fool a name comparison check with an accidental name
> collision:
>
class function(object): # not a reserved name
> ... pass
On Mon, 01 Sep 2008 10:52:10 +0200, Manuel Ebert wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Hi Luca,
>
> use type(something).__name__ , e.g.
>
> >>> def x():
> >>> pass
> >>> class C:
> >>> pass
> >>> c = C()
> >>> type(x).__name__ == 'function'
> True
On Mon, 01 Sep 2008 10:43:25 +0200, Luca wrote:
> Hi all.
>
> I think this is a newbie question... what is the best method to know if
> a property of an object is a function?
>
> I'm thinking something as
>
> if type(obj.methodName)==???
>
> Can someone help me?
That's not quite as easy as yo
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi Luca,
use type(something).__name__ , e.g.
>>> def x():
>>>pass
>>> class C:
>>>pass
>>> c = C()
>>> type(x).__name__ == 'function'
True
>> type(C).__name__ == 'classobj'
True
>> type(c).__name__ == 'instance'
True
On Sep
Hi all.
I think this is a newbie question... what is the best method to know
if a property of an object is a function?
I'm thinking something as
if type(obj.methodName)==???
Can someone help me?
--
-- luca
--
http://mail.python.org/mailman/listinfo/python-list
10 matches
Mail list logo