11 points · by behnamoh · 2y ago · 24 comments
var: str = "Haha"
print(f"{var:_>20}")
print(f"{var:*^20}")
print(f"{str.lower() = }")
def concatenate[T: (str, bytes)](first: T, second: T) -> T:
return first + second
items = [1, 2, 3]
items [:]=[]
items = [1, 2, 3]
items *=0
bowl = ['water']
drink ,= bowl
n = 3
['a', 'b', 'c', *n* ['.']] #> ['a', 'b', 'c', '.', '.', '.']
a, *_ = (1,2,3)My main issue with Python is the whole dependency management/venv situation. It's fine for single app/web-app deployment but when I have a hundred different Python projects on my computer and I need to easily run scripts from them several times a day. My solutions are... not elegant. My current scheme is to start moving my most frequently-used scripts into a monorepo under a single venv.
(recommendations happily accepted)
The only two package managers that have never given me a single headache when installing Python + Torch + CUDA are Nix and Pacman.
Nix will only become a bit problematic to use if you need to package exotic stuff on your own that makes too many assumptions about Unix FHS.
1. No "var" or "let" keyword, which requires you to read code, particularly with loops, more carefully
2. No multi-line lambdas, which forces you to move snippets away from their usage and come up with a name for them
3. Emphasis on classes and annotations over free functions, which is partly due to (2) but also the lack of a pipe operator, like in R
4. Modifying arithmetic operators (*=, +=, ++, --, etc...). These try to do too much at once. Use more intermediate variables and parens; it's much clearer.
5. "with" statement is a decent idea, but it should be usable without increasing nesting
This is a good thing.
> Modifying arithmetic operators (*=, +=, ++, --, etc...)
++ and -- aren't a thing in Python.
https://tio.run/##dY/NDoIwDMfve4oeh4hEvBiT3bj4FAuZRUmWsXTDzK...
No postfix inc/dec though.
Why? Sometimes a mapper or a filter is best split across a few lines but a name adds nothing.
The new type parameter syntax (PEP 695) newly added in 3.12 is certainly busy. I like the feature but I wish there was a better concise syntax. Metatype programming looks ugly in every language I've seen.
The rest of the statements have been around for ages, and I wouldn't call them recent or modern.
def concatenate[T: (str, bytes)](first: T, second: T) -> T:
return first + second
This isn't valid Python. items = [1, 2, 3]
items *=0
bowl = ['water']
drink ,= bowl
a, *_ = (1,2,3)
These are actually useful.None of these are new btw, I don't know about why you're asking the question like it's some new development.
One great thing about Python is that you can do a lot with it but the complexity is gradually exposed to you as you become a more advanced user which makes it both powerful and easy to get into.
As a teenager I’ve been "traumatized" by Pascal, but I was lucky to find a refuge in HTML and CSS. After I got a job as a web designer I discovered Python and I realized that I could actually program.
The people who came up with this new syntax have different needs that I do and probably have a different kind of brain than mine.
I looked up PEP 695 mentioned in another comment.
What do you think?
String formatting.
var: str = "Haha"
print(f"{var:_>20}")
print(f"{var:*^20}")
print(f"{str.lower() = }")
A function declaration with variable types declared. def concatenate[T: (str, bytes)](first: T, second: T) -> T:
return first + second
Should be written like items[:] = []. Here items[:], which is equivalent to items[0:3], is being set to an empty list. items = [1, 2, 3]
items [:]=[]
Extend the list 0 times. So items = [] after this. items *= 2 will create items = [1,2,3,1,2,3]. items = [1, 2, 3]
items *=0
Again, not typical spacing used. drink, = bowl only works if bowl is a list/tuple/etc with only one item. Assigns first element of bowl to drink. Usually written as drink = bowl[0]. bowl = ['water']
drink ,= bowl
# is a comment symbol in python, so ignore all stuff after it. n*['.'] creates ['.', '.', '.']. If we only had ['a', 'b', 'c', n*['.']] (no * before n), then we create ['a', 'b', 'c', ['.', '.', '.']]. The * before n unpacks the inner list so we create ['a', 'b', 'c', '.', '.', '.']. n = 3
['a', 'b', 'c', *n* ['.']] #> ['a', 'b', 'c', '.', '.', '.']
This just assigns a = 1 and assigns _ = (2,3). *_ is syntax for "rest of the list/tuple/sequence/etc". a, \*_ = (1,2,3)Its evolution has always been a sequence of compromises and tradeoffs.
I know it hurts somoeone’s feelings, but the truth is python was created in 80s as a scripting language for average Joe, with 80s mentality that is still there.
Here is just one tiny tip of the iceberg of terrible features of it that makes it a poor choice for any big software
https://news.ycombinator.com/item?id=36661754
For historical, business reasons and because average data scientist, math student are far from being a professional software developer (and also because pythonists downvote and cancel all criticism haha) it is widely popular in AI and scientific community. And rightfully so.
You really don’t think people can do professional demanding work successfully with Python? Or are you aware that professional demanding work is done by people who aren’t you?