pathlib
DL Neil
PythonList at DancesWithMice.info
Mon Sep 30 00:40:38 EDT 2019
Should pathlib reflect changes it has made to the file-system?
Sample code, below, shows pathlib identifying a data-file and then
renaming it. Yet, after the rename operation, pathlib doesn't recognise
its own change; whereas the file system does/proves the change was
actioned.
$ touch before.file
$ python3
Python 3.7.4 (default, Jul 9 2019, 16:48:28)
[GCC 8.3.1 20190223 (Red Hat 8.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
>>> p = pathlib.Path( "before.file" )
>>> p
PosixPath('before.file')
>>> p.name
'before.file'
>>> p.rename( "after.file" )
>>> p.name
'before.file'
>>> exit()
$ ls -lah after*
-rw-rw-r--. 1 dn dn 0 Sep 30 16:05 after.file
$ ls -lah before*
ls: cannot access 'before*': No such file or directory
I would expect pathlib to keep track of changes it has made. Any
ideas/good reasons why/why not?
NB "name" is a r/o attribute.
--
Regards,
=dn
More information about the Python-list
mailing list