5 ms·
Ask HN: What should be added to the syntax of Python and why?
I recently came across the pipe library [0] which allows function chaining in a much more straightforward way:
sum(fib() | where(lambda x: x % 2 == 0) | take_while(lambda x: x < 4000000))
I know in Lisp languages you can extend the syntax easily, but I was wondering if there are any needs for that in Python.
[0] https://pypi.org/project/pipe/
- pid-1 3y agoI don't know the name of this idiom, but the following is valid Python: import pandas as pd my_df = ( pd.Dataframe(<fetch_data>) .join(<...>) .query(<...>) .sort_values(<...>) ) I also use plotly like so: my_plot = ( px.line(<...>) .update_xaxes(<...>) .update_layout(<...) ) Not exactly function chaining, but I guess it has a similar effect. I'm happy with Python's syntax nowadays and much prefer seeing improvements on library / environment related things.
- rowanG077 3y agoIt's called a fluent interface.
- pm2222 3y agoI want braces.
- backslash_16 3y agoI would love separate variable initialization vs assignment. I know that ship has sailed. It's interesting, I never cared about that until I did "Crafting Interpreters" and realized how separating those two actions helps clarify scopes. Being realistic I know it's too large of a breaking change and will never land in the language but I can dream right?
- thek3nger 3y agoNone propagation. It such a pain to constantly check for None when accessing very deep nested structures (as I had to do often with JSON data). There is a PEP for this[1] but it is currently deferred. [1]: https://peps.python.org/pep-0505/ https://peps.python.org/pep-0505/
- mdwalters 3y agoMulti-line lambda. It would be more easier to use than cramming a piece of code into a single line.
- eternityforest 3y agoDitch the general purpose variable annotations thing and make strong typing types first class
- VoodooJuJu 3y agoCurly braces, to make whitespace insignificant. I don't like significant whitespace.
- gabrielsroka 3y agohttps://github.com/umlet/pwk https://github.com/umlet/pwk https://news.ycombinator.com/item?id=25178949 https://news.ycombinator.com/item?id=25178949