for paths, I've been using pathlib, which created pure objects.
It still has a few quirks, but I expect they will be worked out by the next python release.
Here's some examples pay particular attention to the open statement:
It still has a few quirks, but I expect they will be worked out by the next python release.
Here's some examples pay particular attention to the open statement:
>>> from pathlib import Path >>> homepath = Path('.') >>> print(homepath.resolve()) X:\python\m-p\m\MakerProject\venv\src >>> >>> datapath = homepath / 'data' >>> print([file for file in datapath.iterdir()]) [WindowsPath('data/html'), WindowsPath('data/json'), WindowsPath('data/temp')] >>> jsonpath = datapath / 'json' >>> print([file for file in jsonpath.iterdir()]) [WindowsPath('data/json/images.json'), WindowsPath('data/json/images.txt'), WindowsPath('data/json/MakeText.bat'), WindowsPath('data/json/rfc_index.json'), WindowsPath('data/json/rfc_index.txt')] >>> mktxt = jsonpath / 'MakeText.bat' >>> with mktxt.open() as f: ... for line in f: ... print(f) ... <_io.TextIOWrapper name='data\\json\\MakeText.bat' mode='r' encoding='cp1252'> <_io.TextIOWrapper name='data\\json\\MakeText.bat' mode='r' encoding='cp1252'> >>>