How can I dynamically create class methods for a class in python

Question or problem about Python programming: If I define a little python program as class a(): def _func(self): return “asdf” # Not sure what to resplace __init__ with so that a.func will return asdf def __init__(self, *args, **kwargs): setattr(self, ‘func’, classmethod(self._func)) if __name__ == “__main__”: a.func I receive the traceback error Traceback (most recent call […]

Continue Reading
Python Programming

Python vs. Ruby for metaprogramming

Question or problem about Python programming: I’m currently primarily a D programmer and am looking to add another language to my toolbox, preferably one that supports the metaprogramming hacks that just can’t be done in a statically compiled language like D. I’ve read up on Lisp a little and I would love to find a […]

Continue Reading

What is the __dict__.__dict__ attribute of a Python class?

Question or problem about Python programming: >>> class A(object): pass … >>> A.__dict__ >>> A.__dict__.__dict__ Traceback (most recent call last): File “”, line 1, in AttributeError: ‘dictproxy’ object has no attribute ‘__dict__’ >>> A.__dict__.copy() {‘__dict__’: … } >>> A.__dict__[‘__dict__’] # What is this object? If I do A.something = 10, this goes into A.__dict__. What […]

Continue Reading