(04-06-2012, 11:17 PM)Shonumi Wrote: How exactly would I seriously have to rethink my ideas of what an object is? I looked at a lot of Python code, and even had someone at my LUG give a presentation on Python coding, specifically with making your own objects. I don't recall ever having to seriously reorder my understanding of what objects were, in any language.You don't have to. But if you want to profit from the languages' features, you should.
For example, functions are objects in python, so you can re-assign them, for example:
Code:
def f(foo, bar):
print foo, bar
return bar
g = f.__get__(2)
g(5) # prints "2, 5"
def debug_params_and_return_value(function):
def newfunc(*args, **kwargs):
print "Params >> ", args, kwargs
returnValue = function(*args, **kwargs)
print "<< Return", returnValue
return returnValue
return newfunc
f = debug_params_and_return_value(f)
f(3, 5) # prints Params >> (3, 5) {}
# 3 5
# << Return 5Oh, and classes are objects too:
Code:
class foo(): pass
class bar(): pass
prototypes = [foo, bar]
objects = [item() for item in prototypes] # gives a list containing an instance of foo and one of bar
