questions about of writing python scripts

Tim Hammerquist tim at vegeta.ath.cx
Tue Dec 11 02:03:14 EST 2001


Andrew Bennetts <andrew at puzzling.org> graced us by uttering:
> On Sun, Dec 09, 2001 at 05:26:14PM -0800, ed wrote:
>> but c is floating and has not value and a got assgined to it. ...
>> in other compiation lang, this type of error will be caught in
>> compilaiton time, but I can't using python.. is ther any utility
>> or way to catch this type of error way ahead?
> 
> I think what you are looking for is a static analysis tool... try
> pychecker.

I would've just tried the type() function first.

# x is variable
#
# python 2.2 or later:
if type(x) is int:
    print "x is an integer variable"
#
# python 2.1 or earlier:
import types
if type(x) == types.IntType:
    print "x is an integer variable"
#
# types.IntType == type(1) ergo:
if type(x) == type(1):
    print "x is an integer variable"

Just because Python doesn't _force_ type checking doesn't mean it
isn't possible.

Tim Hammerquist
-- 
Reality is that which, when you stop believing in it, doesn't go away.
    -- Philip K. Dick



More information about the Python-list mailing list