by divbzero · 6y ago · 0 comments
– zoneinfo
– dict update operators
– str.removeprefix and str.removesuffix
– “Any valid expression can now be used as a decorator. Previously, the grammar was much more restrictive.”
– “Python now gets the absolute path of the script filename specified on the command line (ex: python3 script.py): the __file__ attribute of the __main__ module became an absolute path, rather than a relative path.”
On the last one I rarely if ever use __file__ as a relative path and have definitely typed os.path.abspath(__file__) many many times.
Good lord, finally! The number of times I've tripped over this.
Because in the context of imports it does: https://docs.python.org/3/tutorial/modules.html#the-module-s...
> Note: On file systems which support symlinks, the directory containing the input script is calculated after the symlink is followed. In other words the directory containing the symlink is not added to the module search path.
"There have been repeated issues on Python-Ideas [2] [3], Python-Dev [4] [5] [6] [7], the Bug Tracker, and StackOverflow [8], related to user confusion about the existing str.lstrip and str.rstrip methods. These users are typically expecting the behavior of removeprefix and removesuffix, but they are surprised that the parameter for lstrip is interpreted as a set of characters, not a substring."
'prix fixe'.lstrip('prefix')
truncating 'prix fixe' to ' fixe'.This case is actually an interesting edge case - I think downvoters are of the mindset that the comment might spread disinformation, therefore it's better to hide it. But I actually agree with you here - this is something a lot of people think, it is wrong, and it's better to explicitly have people see the wrong information, and learn why it's wrong. That's why the PEP itself mentions this as a common misunderstanding!
"aaamap".rstrip("map") != "aaa"