When the regex being compiled in python which has multiple wild cards like plus or asterisks sequentially repeated, you will need to escape or else run into "multiple repeat error". This can happen with any of re module methods like search and sub etc, where the regex is compiled. > > > import re > > > re . compile ( " r++ " ) Traceback ( most recent call last ) : File " <stdin> " , line 1 , in < module > File " /usr/lib/python2.7/re.py " , line 190 , in compile return _compile ( pattern , flags ) File " /usr/lib/python2.7/re.py " , line 242 , in _compile raise error , v # invalid expression sre_constants . error : multiple repeat > > > re . compile ( " r** " ) Traceback ( most recent call last ) : File " <stdin> " , line 1 , in < module > File " /usr/lib/python2.7/re.py " , line 190 , in compile return _...
Class-level variables that are assigned with mutable datatypes are like global static variables, they refer to the same list or dict and can be modified/accessed via multiple instance or through the class itself, >>> class Foo: bar = [] >>> a, b = A(), A() >>> a.bar.append(10) >>> a.bar [10] >>> b.bar [10] >>> Foo.bar [10] >>> class A: def __init__(self): self.bar = [] >>> a, b = A(), A() >>> a.bar.append(10) >>> a.bar [10] >>> b.bar [] >>> Foo.bar Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: type object 'Foo' has no attribute 'bar' To avoid using the same global list/dict across multiple instances we should avoid initializing class/global variables with a mutable datatypes like list/dict
Proxy cannot be created for basic datatypes like list, dict, str and int. Proxy can be create for class instances only. Also proxy cannot be created for proxy of another instance. >>> import weakref >>> a = 'str' >>> b = weakref.proxy(a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot create weak reference to 'str' object >>> a = 1 >>> b = weakref.proxy(a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot create weak reference to 'int' object >>> a = [] >>> b = weakref.proxy(a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot create weak reference to 'list' object >>> a = {} >>> b = weakref.proxy(a) Traceback (most recent call last): File "<stdin>",...
Comments