Should I use a class or dictionary?

Use a dictionary unless you need the extra mechanism of a class. You could also use a namedtuple for a hybrid approach: >>> from collections import namedtuple >>> request = namedtuple(“Request”, “environ request_method url_scheme”) >>> request <class ‘__main__.Request’> >>> request.environ = “foo” >>> request.environ ‘foo’ Performance differences here will be minimal, although I would be … Read more

How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration

Answer coming from : http://grokbase.com/t/gg/rogue-users/1367nscf80/how-to-update-a-record-with-mongocaseclassfield-when-case-class-contains-a-scala-enumeration#20130612woc3x7utvaoacu7tv7lzn4sr2q But more convenient directly here on StackOverFlow: Sorry, I should have chimed in here sooner. One of the long-standing problems with Rogue was that it was too easy to accidentally make a field that was not serializable as BSON, and have it fail at runtime (when you try to add … Read more

Difference between class and type

A class is a type. An interface is a type. A primitive is a type. An array is a type. Therefore, every type is also either a class (including an enum constant), an interface, a primitive, or an array. There are two distinct categories of types: primitive types and reference types: A variable of primitive … Read more

Difference between interfaces and classes in Typescript

2019: Update on Differences and Usages First, there is the obvious difference: syntax. This is a simple, but necessary to understand difference: Interface properties can end in commas or semi-colons, however class properties can only end in semi-colons. Now the interesting stuff. The sections about when to use and not to use may be subjective … Read more

Namespace and class with the same name?

I don’t recommend you to name a class like its namespace, see this article. The Framework Design Guidelines say in section 3.4 “do not use the same name for a namespace and a type in that namespace”. That is: namespace MyContainers.List { public class List { … } } Why is this badness? Oh, let … Read more

How do I implement __getattribute__ without an infinite recursion error?

You get a recursion error because your attempt to access the self.__dict__ attribute inside __getattribute__ invokes your __getattribute__ again. If you use object‘s __getattribute__ instead, it works: class D(object): def __init__(self): self.test=20 self.test2=21 def __getattribute__(self,name): if name==’test’: return 0. else: return object.__getattribute__(self, name) This works because object (in this example) is the base class. By … Read more

Python class definition syntax

While it might not be syntactically incorrect to use the empty parentheses in a class definition, parentheses after a class definition are used to indicate inheritance, e.g: class A(baseClass): … In Python, the preferred syntax for a class declaration without any base classes is simply: class A: … Don’t use parentheses unless you are subclassing … Read more