renames源码:
def renames(old, new):

head, tail = path.split(new) # 作用是分割为两部分,head为路径,tail为文件名;
if head and tail and not path.exists(head): # path.exists(head)检查路径是否存在;
makedirs(head)
rename(old, new)
head, tail = path.split(old)
if head and tail:
try:
removedirs(head)
except OSError:
pass

相同点:
1,重命名时,新路径如果存在,均能在新路径重命名成功,且删除原路径文件;
2,重命名路径下该文件存在时,均报错;
区别:
1,重命名时,新路径如果不存在,os.renames()能新建该路径后重命名文件;而os.rename()则直接报错(报错原因:系统找不到指定的文件);

相关文章:

  • 2021-09-16
  • 2021-07-15
  • 2021-11-30
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
相关资源
相似解决方案