niazangels / road-to-python

This is no royal road. It's full of whatever life hit me.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Road to Python

A collection of wild things I stumbled across that made me go 🤩 or 🤯

NotImplemented signals to the runtime that it should ask someone else to satisfy the operation. In the expression a == b, if a.__eq__(b) returns NotImplemented, then Python tries b.__eq__(a). If b knows enough to return True or False, then the expression can succeed. If it doesn't, then the runtime will fall back to the built-in behavior (which is based on identity for == and !=)

What most people are expecting when they see super(X) is what Python gives you if you do super(X, X).

From simple dictionary with .get() method to really creative ideas like a context manager. Here's one more method

The creator of Flask doesn't due to backpressure

Split your decoration into two

def to_string(value):
    return str(value)

def stringify(func):
    @wraps(func)
    def wrapper(*args):
        return to_string(func(*args))

    return wrapper
git reflog
git reset --hard <sha1 of desired commit>

All NaNs are not equal. Some are butter NaNs.

>>> np.nan == np.nan
False

>>> np.nan is np.nan
True

>>> np.nan in [np.nan]
True

About

This is no royal road. It's full of whatever life hit me.