Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
switching to python3
#2
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:
>>> 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'>
>>>
Reply


Messages In This Thread
switching to python3 - by Skaperen - Feb-20-2018, 02:40 AM
RE: switching to python3 - by Larz60+ - Feb-20-2018, 03:40 AM
RE: switching to python3 - by Skaperen - Feb-20-2018, 03:47 AM
RE: switching to python3 - by Larz60+ - Feb-20-2018, 05:54 AM
RE: switching to python3 - by Skaperen - Feb-22-2018, 06:20 AM
RE: switching to python3 - by Gribouillis - Feb-22-2018, 01:22 PM
RE: switching to python3 - by Skaperen - Feb-23-2018, 06:11 AM
RE: switching to python3 - by Gribouillis - Feb-23-2018, 10:28 AM
RE: switching to python3 - by Skaperen - Feb-24-2018, 03:31 AM
RE: switching to python3 - by Gribouillis - Feb-24-2018, 03:44 AM
RE: switching to python3 - by Skaperen - Feb-25-2018, 02:09 AM
RE: switching to python3 - by Gribouillis - Feb-25-2018, 06:34 AM
RE: switching to python3 - by Skaperen - Feb-25-2018, 07:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  switching from notebook to pycharm enterthevoid22 1 1,767 Oct-10-2020, 05:20 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020