49 karma · joined September 23, 2015
class Base:
def func(self):
print("In Base.func:", self.name)
class Child:
def __init__(self, name):
self.name = name
func = Base.func
c = Child("Foo")
c.func() #=> In Base.func: FooUsing "breakpoints" to describe the /points/ where the layout /breaks/ over is not a new term and quite well understood when talking design / layout.
https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layou...
default = 10
def foo(x=default):
return x
default = 20
assert foo() == 10
I think tat makes a lot of sense.It could also be that the default value is a more ocmplex expression, we could use a function to generate a default argument.
def foo(x=create_default(y, z))
By evaluating it at definition time we only have to evaluate the expression once and not have this weird lazy expression.And yes it is used, for example the fastapi Dependency Injection system has been build quite cleverly using the ability to construct default values
https://fastapi.tiangolo.com/tutorial/query-params-str-valid...
Yes it is one of those things you just have to learn, but there are tons of stuff like that in most programming languages.
It also works for python2. I try to avoid using python tools that installs their own scripts and go for calling the module through python. This also works for python3/2 -m venv venv
I am kind of developing a grudge against whitespace sensitive languages. Not because it forces the programmer to indent properly, but because it disables my editors abilities to do it for me.