You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromshutilimportmovefrompathlibimportPatha=Path("s")
b=Path("a.txt")
move(b, a)
This will throw AttributeError: 'WindowsPath' object has no attribute 'rstrip'
From the document, it should able to move:
If the destination is an existing directory, then src is moved inside that directory. If the destination already exists but is not a directory, it may be overwritten depending on os.rename() semantics.
This issue isn't specific to Windows. It's a bug in shutil._basename:
def_basename(path):
# A basename() variant which first strips the trailing slash, if present.# Thus we always get the last component of the path, even for directories.sep=os.path.sep+ (os.path.altsepor'')
returnos.path.basename(path.rstrip(sep))
It should use os.fspath(path) to get the path as a string.
Activity
joshuaavalon commentedon Jul 8, 2018
This will throw AttributeError: 'WindowsPath' object has no attribute 'rstrip'
From the document, it should able to move:
If the destination is an existing directory, then src is moved inside that directory. If the destination already exists but is not a directory, it may be overwritten depending on os.rename() semantics.
If a = Path("s/a.txt"), it does not throw error.
Enviroment:
Window 10
Python 3.7.0
eryksun commentedon Jul 8, 2018
This issue isn't specific to Windows. It's a bug in shutil._basename:
It should use
os.fspath(path)to get the path as a string.[-]Fail to move file in Windows (AttributeError)[/-][+]shutil.move fails with AttributeError[/+]berkerpeksag commentedon Jul 8, 2018
This is a duplicate of bpo-32689.
PR 5393 already does that.