3 ms·
Lots of ridiculously bad advice here, every single code snippet does something idiotic! The whole article should be replaced by two words: "import inspect" Thi
by blasdel 17y ago
Lots of ridiculously bad advice here, every single code snippet does something idiotic! The whole article should be replaced by two words: "import inspect"
This snippet was particularly shit:
>>> var1 = 12
>>> typ = str(type(var1))
>>> if typ == "":
... var1 / 4
... else: print 'Not an Int'
This is wrong on so many levels! For starters, it doesn't work at all -- why the hell does he think typ won't be "<type 'int'>"?
Second, if you're going to use the type builtin for this, why the fuck would you cast it to a string, when "if type(var1) is int" works just fine?
Third, don't ever use the 'type' built-in for this kind of type-checking -- this is what the 'isinstance' built-in is for. 'type' chokes completely on old-style classes, and doesn't handle inheritance at all.
- tdavis 17y agoYes. Please don't do this stuff. Like, ever. Except the really twisted road taken to show that functions are first-class objects and can be passed around. That's useful. I've ran into this particular site before and something about it just rubs me wrong. In this case that "something" is rather obvious.