我使用此代码将项目移动到另一个文件夹中
import os
files = os.listdir('C:/Users/EL127032/youtube-downloader-converter')
print(files)
numbertocheck = 0
numberoftimes = len(files)
while numbertocheck != numberoftimes:
if any("mp3" in s for s in files):
filechecking = files[numbertocheck]
if "mp3" in filechecking():
oldfilepath = ("C:/Users/EL127032/youtube-downloader-converter/" + filechecking)
newfilepath = ("C:/MuziekMP3/" + filechecking)
os.rename(oldfilepath, newfilepath)
numbertocheck = numbertocheck + 1但是当我运行这个的时候,我得到了
File "C:\Users\EL127032\PycharmProjects\pythonProject2\main.py", line 12, in <module>
if "mp3" in filechecking():
TypeError: 'str' object is not callable发布于 2021-06-12 17:36:46
在第12行(如错误消息所示),您拥有:
...
if "mp3" in filechecking():
...filechecking后面的圆括号将使解释器假定它是一个需要调用的函数。
但是,filechecking是一个包含您感兴趣的文件名的str (字符串)。
只需删除()或将其更改为类似以下内容:
...
if filechecking.endswith(".mp3"):
...再试一次。
https://stackoverflow.com/questions/67946789
复制相似问题