Checking variable types in Python Script
Hi, How do I use type() in Python scripts. It seems that type() is restricted code (why?) is there any special replacement for type checking? Regards, Johan Carlsson (It's hard living in a dynamically type world if you can check for type :-) -- Torped Strategi och Kommunikation AB Johan Carlsson johanc@torped.se Mail: Birkagatan 9 SE-113 36 Stockholm Sweden Visit: Västmannagatan 67, Stockholm, Sweden Phone +46-(0)8-32 31 23 Fax +46-(0)8-32 31 83 Mobil +46-(0)70-558 25 24 http://www.torped.se http://www.easypublisher.com
Johan Carlsson [Torped] <johanc@torped.se> wrote:
How do I use type() in Python scripts. It seems that type() is restricted code (why?) is there any special replacement for type checking?
You use same_type(foo, bar). Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
Johan Carlsson [Torped] writes:
How do I use type() in Python scripts. You do not, it is private. It seems that type() is restricted code (why?) It would confuse many users.
is there any special replacement for type checking? There is "same_type(object,sample)". It tests whether "object" and "sample" are of the same type.
For Zope objects, you can use "meta_type" (which will usually (but not always) give good results). Dieter
At 20:41 2002-09-09 +0200, Dieter Maurer said:
Johan Carlsson [Torped] writes:
is there any special replacement for type checking There is "same_type(object,sample)". It tests whether "object" and "sample" are of the same type.
That would do the trick. But I would like to have special type checking API in Python scripts. E.g. isString, isTuple, isList, etc. That's my 5 cents anyway. I would find that less confusing. But that a whole different mailing list :-) Regards, Johan Carlsson -- Torped Strategi och Kommunikation AB Johan Carlsson johanc@torped.se Mail: Birkagatan 9 SE-113 36 Stockholm Sweden Visit: Västmannagatan 67, Stockholm, Sweden Phone +46-(0)8-32 31 23 Fax +46-(0)8-32 31 83 Mobil +46-(0)70-558 25 24 http://www.torped.se http://www.easypublisher.com
Johan Carlsson[ Torped] writes:
At 20:41 2002-09-09 +0200, Dieter Maurer said:
There is "same_type(object,sample)". It tests whether "object" and "sample" are of the same type.
That would do the trick.
But I would like to have special type checking API in Python scripts. E.g. isString, isTuple, isList, etc. That's my 5 cents anyway. "same_type(x,'')", "same_type(x,())", "same_type(x,[])" ...
Why do you want a whole set of new names? Dieter
On Mon, Sep 09, 2002 at 08:41:02PM +0200, Dieter Maurer wrote:
Johan Carlsson [Torped] writes:
How do I use type() in Python scripts. You do not, it is private. It seems that type() is restricted code (why?) It would confuse many users.
Er... sorry, I don't buy that (actually, your answer has got me all confused myself ;-) I'd expect that there be a security thing involved somewhere (I don't see it right now, but who knows what you can do with a type object...) Thanks -- tomas
I believe it would confuse users because everything at the python level wrapped up in aquisition magic, so the standard type stuff would be useless. Myabe there is a security issue but I can't imagine what it would be.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of tomas@fabula.de Sent: Tuesday, September 10, 2002 1:12 AM To: Dieter Maurer Cc: zope@zope.org Subject: Re: [Zope] Checking variable types in Python Script
On Mon, Sep 09, 2002 at 08:41:02PM +0200, Dieter Maurer wrote:
Johan Carlsson [Torped] writes:
How do I use type() in Python scripts. You do not, it is private. It seems that type() is restricted code (why?) It would confuse many users.
Er... sorry, I don't buy that (actually, your answer has got me all confused myself ;-)
I'd expect that there be a security thing involved somewhere (I don't see it right now, but who knows what you can do with a type object...)
Thanks -- tomas
From: "Charlie Reiman" <creiman@kefta.com>
I believe it would confuse users because everything at the python level wrapped up in aquisition magic, so the standard type stuff would be useless.
Ah, so the problem is not security, or that it's confusing, but that it doesn't really work. :-) Best Regards Lennart Regebro, Torped http://www.easypublisher.com/
participants (6)
-
Charlie Reiman -
Dieter Maurer -
Florent Guillaume -
Johan Carlsson [Torped] -
Lennart Regebro -
tomas@fabula.de