3 回答
TA贡献1818条经验 获得超3个赞
该replace
方法采用两个强制参数:
你
substring
想要替换的新价值
所以,改变这个
name = name.replace (name_change)
到
name = name.replace(name, name_change)
TA贡献1829条经验 获得超7个赞
你可以试试这个:
def staff_info(name):
print("So you are " + name + ", years old. ")
name = input("Type your name: ")
confirm_info = input("So you have " + name + ". Confirm that? (Yes/No) ")
if confirm_info == "Yes":
print("Okay so I have few more question for you. ")
elif confirm_info == "No":
change_info = input("So what do you want to change? ")
if change_info != name:
name_change = input("Type the name you want to change: ")
new_name = name_change.replace(name, name_change)
print("New Name = ", new_name)
else:
print("...")
TA贡献2051条经验 获得超10个赞
这是我用来重命名文件的
import os
path=r''
def startRename():
files=os.listdir(path)
count=1
for file in files:
os.rename(f"{path}\{file}",f"{path}\{count}.wav")
count+=1
startRename()
添加回答
举报