3 ms·
Intro to Python Introspection and Dynamic Programming
- uggedal 17y agoHello webdesign and banner-ads from 1999. At least put some effort into syntax highlight your code samples.
- blasdel 17y agoLots 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.
- scott_s 17y ago"You keep using that word. I do not think it means what you think it means": http://en.wikipedia.org/wiki/Dynamic_programming http://en.wikipedia.org/wiki/Dynamic_programming