I think many people get imprinted with writing the PY3 code using only the features available at the time they switched over.
And collections.ChainMap.
And f-strings.
And yield from.
And type hints.
And statistics.
And ipadress.
And secrets.
And matmul.
And subprocess.run.
Come on, Python 3 is packed with awesomeness !
What you have is decision making analogous to the function
evaluate(string_interpolation, python_ecosystem)
which is different from evaluate(string_interpolation)This argument won't fly. Did you know that string interpolation in Perl and shell was always an opt-in feature? And despite that it was frowned upon by Python community.
While certainly awesome, these are in python 2.7 as well. Although I don't remember if they where in 2.7 first of back-ported to 2.7 from 3.
> Previously it was always tempting to use string concatenation (concise, but obviously bad), now with pathlib the code is safe, concise, and readable.
This is the kind of feature that I'm wary to use even in scripts: questionable benefit, and probably too clever.
It's not like programs consist of path operations to a significant degree, so using fancy syntactic sugar doesn't seem like a worthwhile optimization to me. At all.
>>> Path.cwd() / 1
TypeError: argument should be a path or str object, not <class 'int'>
Also, note that the '/' operator is left-associative, so even if you have two adjacent numbers when joining paths, there will be no division. TypeError: expected str, bytes or os.PathLike object, not int >>> from pathlib import Path
>>> p=Path(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/pathlib.py", line 979, in __new__
self = cls._from_parts(args, init=False)
File "/usr/lib/python3.6/pathlib.py", line 654, in _from_parts
drv, root, parts = self._parse_args(args)
File "/usr/lib/python3.6/pathlib.py", line 638, in _parse_args
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not int
>>>
So what happens if the paths are numbers? They are treated like any other characters.Python is strongly typed.
Should I have said "numeric characters" or "numeric strings" in my last paragraph instead of numbers?