8 ms·
the Path thing is incredible! I wasn't aware of it. I'll definitively be replacing my os.path.join calls for a more readable version of it.
by coppolaemilio 9y ago
the Path thing is incredible! I wasn't aware of it. I'll definitively be replacing my os.path.join calls for a more readable version of it.
- ioddly 9y agoWow, I switched to Python 3 really early on and never knew about pathlib.
- has2k1 9y agoI have been conditioned to write code that is 2/3 compatible, that even when I am writing specifically for the PY3 interpreter the code turns out to be a __future__ import away from being valid PY2. I did not think much of them at first, but very recently, f-strings have changed that. I think many people get imprinted with writing the PY3 code using only the features available at the time they switched over.
- orf 9y agoYou can use some backports of libraries though, surely? `pathlib` is in pip.
- has2k1 9y agoBack-ports are an option but they are an extra dependency. When you have not used a new feature, the cost of an extra dependency out weighs the unknown benefits that would be realised by using a back-port.
- sametmax 9y agoAnd the multiprocessing and threading pools. 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 !
- dozzie 9y agoEvery time somebody mentions how awsome f-strings are makes me laugh. It was around ten years ago when Python community was looking down at Perl and shell with their string interpolation, but now that Python got pretty much the same it's suddenly not considered a misfeature.
- has2k1 9y agoHave you considered that maybe the language had not evolved enough for them to be appealing. With b'' and u'' string syntax coming into the language, there is a realisation that string interpolation can be an opt-in feature among other reasons. What you have is decision making analogous to the function evaluate(string_interpolation, python_ecosystem) which is different from evaluate(string_interpolation)
- dozzie 9y ago> With b'' and u'' string syntax coming into the language, there is a realisation that string interpolation can be an opt-in feature among other reasons. 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.
- sametmax 9y agoWe were wrong. We aknowledged it and improved. It's a good thing.
- dagw 9y agomultiprocessing and threading pools 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.
- sametmax 9y ago__Reliable__ pools are only in 3.
- quietbritishjim 9y agoThe read_bytes() and read_text() methods are particularly useful. They're new in Python 3.5.
- jstimpfle 9y ago> test_path = datasets_root / dataset / 'test' > 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.
- metaobject 9y agoI don't have a machine available right now, but I wonder what happens if two adjacent path elements are integers? Does it perform division instead of path/string concatenation?
- lgas 9y agoTypeError: expected str, bytes or os.PathLike object, not int
- maxerickson 9y agoThe Path object won't construct a path from an integer. >>> 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.
- sametmax 9y agoPath(__file__).absolute().parent.glob('/*.py') is just wonderful.