【发布时间】:2017-04-25 22:18:20
【问题描述】:
假设这是我的 numpy 文件的名称:
File1.npy
File2.npy
我需要修改文件名,添加一条重要信息:
File1_SV1. npy
File2_SV2
我尝试使用这行代码:
path ='C:\\Users\\mky\\Folder'
Files= os.listdir(path)
for File in Files:
SV= # I must calculate the SV
os.rename(os.path.join(path,File), os.path.join(path, File+SV))
它给了我这个错误:
os.rename(os.path.join(path,File), os.path.join(path, File+SV))
TypeError: must be str, not int
【问题讨论】:
-
将
SV转换为字符串 -
可能
SV是一个整数而不是字符串。您可以通过使用str()文字将其转换为字符串。即str(SV).