python Programming Glossary: bases
What is a metaclass in Python? http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python this class UpperAttrMetaclass type def __new__ cls clsname bases dct uppercase_attr for name val in dct.items if not name.startswith.. uppercase_attr name val return type.__new__ cls clsname bases uppercase_attr We can make it even cleaner by using super which.. type class UpperAttrMetaclass type def __new__ cls clsname bases dct uppercase_attr for name val in dct.items if not name.startswith..
__lt__ instead of __cmp__ http://stackoverflow.com/questions/1061283/lt-instead-of-cmp multiply inherit from ComparableMixin after whatever other bases it needs if any . A class decorator would be quite similar just..
convert integer to a string in a given numeric base in python http://stackoverflow.com/questions/2267362/convert-integer-to-a-string-in-a-given-numeric-base-in-python solution that can be called the same way for different bases I want to allow bases other than 2 8 16 Related Python elegant.. be called the same way for different bases I want to allow bases other than 2 8 16 Related Python elegant inverse function of..
Final classes in Python 3.x- something Guido isn't telling me? http://stackoverflow.com/questions/2825364/final-classes-in-python-3-x-something-guido-isnt-telling-me 3.x quite easily class Final type def __new__ cls name bases classdict for b in bases if isinstance b Final raise TypeError.. Final type def __new__ cls name bases classdict for b in bases if isinstance b Final raise TypeError type ' 0 ' is not an.. base type .format b.__name__ return type.__new__ cls name bases dict classdict class C metaclass Final pass class D C pass will..
Dynamically adding @property in python http://stackoverflow.com/questions/2954331/dynamically-adding-property-in-python
How does Python's super() work with multiple inheritance? http://stackoverflow.com/questions/3277367/how-does-pythons-super-work-with-multiple-inheritance raise an error TypeError Error when calling the metaclass bases Cannot create a consistent method resolution order MRO for bases..
What kinds of patterns could I enforce on the code to make it easier to translate to another programming language? http://stackoverflow.com/questions/3455456/what-kinds-of-patterns-could-i-enforce-on-the-code-to-make-it-easier-to-translat instead of simply doing a manual conversion for small code bases e.g. up to about 100K SLOC in our experience the economics simply..
What is the __dict__.__dict__ attribute of a Python class? http://stackoverflow.com/questions/4877290/what-is-the-dict-dict-attribute-of-a-python-class that are specific to it and not defined in one of its bases. By default an var cls of an empty class carries three descriptors..
How to convert an integer to the shortest url-safe string in Python? http://stackoverflow.com/questions/561486/how-to-convert-an-integer-to-the-shortest-url-safe-string-in-python You should be able to easily adapt this code to different bases by changing the alphabet either to restrict it to only alphanumeric..
inspect.getmembers() vs __dict__.items() vs dir() http://stackoverflow.com/questions/6761106/inspect-getmembers-vs-dict-items-vs-dir of its attributes and recursively of the attributes of its bases. Otherwise the list contains the object ™s attributes names the..
Python Class Decorator http://stackoverflow.com/questions/681953/python-class-decorator args kwargs pass class FooMeta type def __new__ cls name bases attrs attrs '__init__' substitute_init return super FooMeta.. substitute_init return super FooMeta cls .__new__ cls name bases attrs class Foo object __metaclass__ FooMeta def __init__ self..
How can I intercept calls to python's “magic” methods in new style classes? http://stackoverflow.com/questions/9057669/how-can-i-intercept-calls-to-pythons-magic-methods-in-new-style-classes attributes class __metaclass__ type def __init__ cls name bases dct def make_proxy name def proxy self args return getattr.. self._obj name return proxy type.__init__ cls name bases dct if cls.__wraps__ ignore set __ s__ n for n in cls.__ignore__.split..
|