阅读更多
Submitted by: peterbe
Last Edited: 2004-10-14
Category: Python(Script)
Average rating is: 4.17 out of 5 (6 ratings)
Description:
You can't use type() or the types modules in Python Script because "The 'type' function, on the other hand, causes
a security hole when used with ExtensionClasses" (Evan Simpson).
Instead you use the Python Script builtin same_type()::
same_type(variable1,variable2)
Source (Text):
# in an external method
if type(variable)==type([]):
print "it's a list"
# in a Python Script
if same_type(variable,[]):
print "it's a list"
# just the same
s = "a string"
t = ("a string",)
l = ["a string"]
print same_type(s,t) # returns 0
print same_type(s,l) # returns 0
print same_type(s,t[0]) # of course returns 1