Hacker Newsnew | past | comments | ask | show | jobs | submit | metrognome's commentslogin

Zen of Python in 2025:

  There should be one-- and preferably only one --obvious way to do it.
Python String Formatting in 2025:

- t-strings

- f-strings

- %-operator

- +-operator

- str.format()


And $-strings (PEP 292) as well. :-)

I see each of these as distinct but overlapping; I'm (slowly) writing a guide to string formatting with all of these in mind, trying to emphasize when I'd choose one over the other. (fwiw I personally avoid % and + these days; $ is pretty uncommon in practice; f-, t-, and .format() all seem to have good unique uses.)


The last three generally shouldn't be used (`+` is sometimes fine, but not really for formatting), but I doubt we would ever get a py4 that removes them, given the stomachaches that py3 caused. It does feel odd that a t-string is just an f-string without args applied.


It's my understanding that they're still recommended for logging since with f-strings you always pay the formatting cost (but with str.format it's deferred).


t-strings aren't really like these others.

It's definitely true that those four string formatting techniques violate the "one obvious way" advice.


I could scarcely believe this new t-string wasn't a joke. As an occasional, grudging Python programmer, I rue the accretion of string formatters over the years. My code bears the history of successive, imperfectly understood (by me)formatters.

"Situation: There are 14 competing standards...." https://xkcd.com/927/


I'm surprised that there's been no mention of Operation Paperclip, neither in the article nor in the comments here. Seems like a huge part of the story to leave out.

https://en.m.wikipedia.org/wiki/Operation_Paperclip


Hard to overstate how much effort the US put into collecting all the best scientists in the post WWII world.


Yes, including surrounded and forcibly brought them into US camps. But yeah, the Soviets did the same and we had the nuclear bomb race, the space race and the Cold War.


This is the first thing that struck me. Dangerous to weave narratives where large scale phenomena are elegantly explained by a single cause. It's always a confluence of multiple factors: influx of Nazi scientists, the policy mentioned in the article, the fact that Europe was recovering from a war, and perhaps others we're failing to notice.

A favorite example of mine is the idea that World War 1 would not have happened if only Duke Ferdinand's driver had been told of the route change during the Sarajevo visit.


I'm going to leave this here for anyone who wants some good focus-time music: https://youtu.be/Do5_wU9X1pc


It's about writing code that your peers can read. "DO NOT SUBMIT" is clear as day. "ASDFASD" probably does not mean "this is a debugging string" to most people.


I live in an apartment complex that uses RealPage. My roommates and I re-signed the lease earlier this year, with a projected 15% rent price increase. We then walked to our leasing office to ask about it, they simply cancelled the increase. We're now paying the same rate we were last year.

I am fairly certain that 15% increase was the automatic recommendation by RealPage.


It may have been an illegal increase, any apartment built before 2018 in Ontario is subject to rent control, 2.5% was the max this year.

RealPage would only have an affect on new leases with new apartments.

Your lease does not renew, it automatically goes month to month. They can't cancel a lease, they would need a reason to evict and apply for it at the LTB.


I live in California.


According to the article, he disappeared in 1976 (48 years ago). Apologies for the pedantry.


At the time he was declared legally dead it had been 10 years.


they mean at time of being declared legally dead (1986) it's been 10 years since he disappeared (1976)


I'm pretty sure that the GP understood that, and was just being nitpicky about grammar. It's incorrect grammar to say "it has been 10 years" in this case.


There are plenty of projects smaller than the Linux kernel that have developed and employed DSLs (to varying degrees of success, I'll grant). I wonder, are there any languages out there designed specifically for kernel programming?

Given the number of preprocessor hacks used in the kernel, and the amount of GCC-specific behavior that the codebase depends on, it seems like they are already halfway there.


Honestly, they'd probably be better off if they ditched all the sed/awk/macro BS and just went back to bash scripts (or perl/TCL, if you don't like weird syntax issues) that spat out C code. Rust saw the writing on the wall and implemented proc macros.

Stop using tiny hammers and get a big one.


I gained a a few years of experience in SQL-based OLAP systems at my current job. In this time I developed a strong appreciation for SQL, especially for its composability. Recently, I started a project in Google Colab, gluing together queries from several systems with Pandas DataFrames. I can honestly say that I've never been more frustrated learning an API than I have with Pandas.

Need some window function like LAG() or LEAD()? Too bad, I hope you like writing Python "for i in range(...):" loops. My notebook is littered with ".reset_index()" calls, ".replace(np.nan, None)", "axis='columns'", "foo.assign(bar=lambda df: df.apply(lambda row: ...))". groupby is especially confusing to me, as a Pandas GroupBy is difficult to compose with a normal DataFrame until you call .reset_index(). Compare this to SQL, where a subquery is a subquery, whether or not it has a GROUP BY clause.

The Pandas documentation also leaves a lot to be desired. Take the documentation of pandas.NaT[1] for example. "pandas.NaT: alias of NaT". Ok? That still doesn't tell me what NaT is, nor does it link to the thing that it aliases. The groupby documentation[2] also caused me some headaches, as it covers only the simplest aggregation use-cases.

Pandas is clearly better for some use-cases, but mostly for simple operations that are well-supported by the API (perhaps numeric operations that are implemented with native numpy routines). But if I'm doing some interactive OLAP stuff, I'll reach for SQL. Perhaps the problem is I'm trying to use Pandas like it's SQL, when it's not. But for manipulating data, I'd rather use a language than a library.

[1] https://pandas.pydata.org/docs/reference/api/pandas.NaT.html [2] https://pandas.pydata.org/docs/user_guide/groupby.html

edit: half a sentence


I should've specified polars, ibis, dplyr, pyspark, etc.

Pandas is easily the worst dataframe api.

I'll never go back to SQL from polars, it's far superior in both composability and readability imo.

Not to mention complex transforms can be version controlled and unit tested, and then you can compose these together.

It also maps to/from SQL quite naturally.


Remember everyone, your bubbles are green because you have an iPhone, not because the person you are texting has an Android.


For the mixing and mastering aspect of music production, look no further than Dan Worrall:

https://www.youtube.com/playlist?list=PL6e8wfdmIuLEDpO3rd5jO...

https://www.youtube.com/playlist?list=PLNNHQbT3rbzXwLY0E_-o9...


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: