3 ms·
The Path object won't construct a path from an integer. >>> from pathlib import Path >>> p=Path(1) Traceback (most recent call last): File "<
by maxerickson 9y ago
The 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 agop=Path(str(1)) Python is strongly typed.
- maxerickson 9y agoYes, that's pretty much the question metaobject was asking. Should I have said "numeric characters" or "numeric strings" in my last paragraph instead of numbers?