1
下面的代码只是想打印的所有文件的名称在目录:为什么python 3.4中的path.name()给我“TypeError:'str'对象不可调用?”?
from pathlib import Path
for myPath in Path.cwd().iterdir():
print (myPath.name())
它给我的错误:
Traceback (most recent call last):
File "NameTest.py", line 4, in <module>
print (myPath.name())
TypeError: 'str' is not callable
如果我打印“mypath中”对象类型,一切在目录中返回类pathlib.windowspath。
我在最新版本的parallels的Windows 8上使用Python 3.4。
谢谢!我不知道为什么我没有看到。 –
'Path(your_path).parent' - >'parent'和'name'是str类型,不应该作为函数调用() –