Re: [Tutor] question re type()

2007-10-31 Thread Aditya Lal
On 10/31/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > > Aditya Lal wrote: > > On 10/29/07, *Kent Johnson* <[EMAIL PROTECTED] > > wrote: > > > - Common Python practice is to prefer the least restrictive type > check > > possible. > > > I completely agree that the c

Re: [Tutor] question re type()

2007-10-31 Thread Kent Johnson
Aditya Lal wrote: > On 10/29/07, *Kent Johnson* <[EMAIL PROTECTED] > > wrote: > - Common Python practice is to prefer the least restrictive type check > possible. > I completely agree that the check " type(n) == int " is very intuitive > and simple. Its just th

Re: [Tutor] question re type()

2007-10-30 Thread Aditya Lal
On 10/29/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > > Aditya Lal wrote: > > or use types module > > > > import types > > > > if type(n) == types.IntType or type(n) == types.LongType : > > blah! > > A few notes: > - If you look at types.py, you find > IntType = int > LongType = long > > and s

Re: [Tutor] question re type()

2007-10-29 Thread Kent Johnson
Aditya Lal wrote: > or use types module > > import types > > if type(n) == types.IntType or type(n) == types.LongType : > blah! A few notes: - If you look at types.py, you find IntType = int LongType = long and so on for all the built-in types, so there is no need or advantage to importin

Re: [Tutor] question re type()

2007-10-27 Thread Dick Moores
At 11:34 AM 10/27/2007, Dave Kuhlman wrote: >On Sat, Oct 27, 2007 at 01:03:18PM +0100, Alan Gauld wrote: > > > if type(n) == int > > > > Or just use an instance of the same type: > > > > if type(n) == type(42) > >Calling type(n) for any integer seems to return the same object. >I checked with id().

Re: [Tutor] question re type()

2007-10-27 Thread Alan Gauld
"Dave Kuhlman" <[EMAIL PROTECTED]> wrote > Calling type(n) for any integer seems to return the same object. > I checked with id(). I would hope so since they are all of the same type. It thus makes sense that they all return a reference to the same type object. > So, should we be using: > >

Re: [Tutor] question re type()

2007-10-27 Thread Dave Kuhlman
On Sat, Oct 27, 2007 at 01:03:18PM +0100, Alan Gauld wrote: > > "Dick Moores" <[EMAIL PROTECTED]> wrote > > > if type(n) == 'int' or type(n) == 'long': > > do something > > don't use strings > > if type(n) == int > > Or just use an instance of the same type: > > if type(n) == type(42) Call

Re: [Tutor] question re type()

2007-10-27 Thread Aditya Lal
On 10/27/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > > "Dick Moores" <[EMAIL PROTECTED]> wrote > > > if type(n) == 'int' or type(n) == 'long': > > do something > > don't use strings > > if type(n) == int > > Or just use an instance of the same type: > > if type(n) == type(42) > > Alan G. > > __

Re: [Tutor] question re type()

2007-10-27 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote > if type(n) == 'int' or type(n) == 'long': > do something don't use strings if type(n) == int Or just use an instance of the same type: if type(n) == type(42) Alan G. ___ Tutor maillist - Tutor@python.o

Re: [Tutor] question re type()

2007-10-27 Thread Dick Moores
At 04:34 AM 10/27/2007, Ricardo Aráoz wrote: >Just take the quotes off : > >if type(n) == int or type(n) == long : Thanks. I tried a lot of things, but not that one! Dick >HTH Oh, yeah! ___ Tutor maillist - Tutor@python.org http://mail.python.org/

Re: [Tutor] question re type()

2007-10-27 Thread Ricardo Aráoz
Dick Moores wrote: > I can't figure out how to test a variable n for its type. > > An example that is the wrong syntax, but shows what I want to do: > > if type(n) == 'int' or type(n) == 'long': >do something > > elif type(n) == 'float': >do something else > > elif type(n) == 'str': >

[Tutor] question re type()

2007-10-27 Thread Dick Moores
I can't figure out how to test a variable n for its type. An example that is the wrong syntax, but shows what I want to do: if type(n) == 'int' or type(n) == 'long': do something elif type(n) == 'float': do something else elif type(n) == 'str': do something different What's the correc