By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,270 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,270 IT Pros & Developers. It's quick & easy.

Set type?

P: n/a
_
How do you check to see if a variable is a set? I would like to use

if type(var) is types.SetType:
blah

but that is not available in types module. I am using 2.4

Jan 4 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I've seen people do that using an exception, e.g.

try:
foo
except :
#variable foo not defined
On Jan 4, 2007, at 10:48 AM, _ wrote:
How do you check to see if a variable is a set? I would like to use

if type(var) is types.SetType:
blah

but that is not available in types module. I am using 2.4

--
http://mail.python.org/mailman/listinfo/python-list
Jan 4 '07 #2

P: n/a
_ wrote:
How do you check to see if a variable is a set? I would like to use

if type(var) is types.SetType:
blah

but that is not available in types module. I am using 2.4
In [1627]: type(set()) is set
Out[1627]: True

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Jan 4 '07 #3

P: n/a
_ wrote:
How do you check to see if a variable is a set? I would like to use

if type(var) is types.SetType:
blah

but that is not available in types module. I am using 2.4
# set or subclass of set
if isinstance(var, set):
...

# exact match
if type(var) is set:
...

also see

http://preview.tinyurl.com/yjnoc5

</F>

Jan 4 '07 #4

P: n/a

Fredrik Lundh wrote:
if type(var) is types.SetType:
blah

but that is not available in types module. I am using 2.4

# set or subclass of set
if isinstance(var, set):
...
or
if isinstance(var, (set, frozenset)):
...

-Mike

Jan 4 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.