Live data from Hacker News

Be Careful with Python's New-Style String Format

lucumr.pocoo.org

1–10 of 155 posts

Re: Be Careful with Python's New-Style String Format

#8
post #5

I do love writing python, but it's pretty shocking when I find out you can write something like `event.__init__.__globals__[CONFIG][SECRET_KEY]`. That language just does not care about privacy or information hiding at all, I guess.

Python's general mentality can be summed as "We are all consenting adults here". If you want to access some part of program or data, you generally can, but the burden of not breaking anything while messing with internals is on you.

This is a great power, but also can become an unlimited source of bugs.

Re: Be Careful with Python's New-Style String Format

#9
No, Rust does not have the ability to access any variable in the program via a format string. Rust has this:

   format!("{argument}", argument = "test");   // => "test"
That's just named arguments to the format. Also, that's a macro; it's expanded at compile time.

Python's approach is lame. It should have used something with a limited list of named arguments, or maybe a dict.

Post reply on HN