2.2 features
John Schmitt
jschmitt at vmlabs.com
Fri Jul 27 14:27:57 EDT 2001
Why do we have to wait for 2.2? You can do this already.
PythonWin 2.1 (#15, Apr 19 2001, 10:28:27) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (MarkH at ActiveState.com) - see
'Help/About PythonWin' for further copyright information.
>>> import types
>>> types.IntType
<type 'int'>
>>> assert isinstance(0,types.IntType)
>>> assert isinstance([],types.IntType)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AssertionError
>>>
> -----Original Message-----
> From: Guido van Rossum [mailto:guido at python.org]
> Sent: Thursday, July 26, 2001 7:10 AM
> To: python-list at python.org
> Subject: Re: 2.2 features
>
>
> "Nick Perkins" <nperkins7 at home.com> writes:
>
> > Here's a nice little use of type/class unification:
> >
> > instead of using:
> > if type(x) is type(0):
> >
> > we can use:
> > if type(x) is int:
> >
> > or, for type checking..
> >
> > assert type(num) is int
> > assert type(msg) is str
> >
> > ( I assume the use of 'is', rather than '==', is acceptable here )
>
> Yes, 'is' is right. But you should never use this; instead, you
> should use
>
> assert isinstance(num, int)
> assert isinstance(msg, str)
>
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list