4 ms·
> you have to do foo.get('bar')... or in some cases getattr(foo, 'bar', None) This is a mistake based on thinking in Javascript: in JS the index operator is ef
by jchw 7y ago
> you have to do foo.get('bar')... or in some cases getattr(foo, 'bar', None)
This is a mistake based on thinking in Javascript: in JS the index operator is effectively the same as the dot operator, for example foo[“bar”] == foo.bar. In Python those are different. [] corresponds to get in dicts, and . corresponds to getattr in objects.
My personal biggest gripe with Python is that there isn’t a better story for typing as I’m spoiled by TypeScript and static languages that have a better development experience and prevent certain classes of mistakes.
- snypox 7y agoHow about post 3.5 type hints?
- jchw 7y agoEvery time I mention typing in Python, people point out the existence of type hints and type checkers. However, I’ve yet to be able to meaningfully use one in practice. I have used MyPy but it didn’t offer nearly as much benefit as say, TypeScript, and brought problems of its own. There’s been some work done but for example, Django middleware is problematic here. A lot of Pythonic code would be extremely challenging to actually cover with robust typechecking. Not to mention, a lot of software treats type hints very differently. PyCharm is able to do powerful inference that MyPy can’t do.