double backslash python os.path.abspath

与世无争的帅哥 提交于 2019-12-11 23:19:48

问题


I get the path

dire=os.path.abspath(".")

and

for fileName in filter(os.path.isfile, os.listdir(path=direc))

but dire has C:\\ and sends me the next error:

TypeError: listdir() takes no keyword arguments

when I print dire to see the content print next:

C:\\user\\documents....

what can I do to get \ and not \\ in os.path.abspath(".")?


回答1:


I'm assuming that by print you mean repr.

s = 'C:\\'
s
>>> 'C:\\'
print(s)
>> C:\

Note that while printing there aren't neither double \\ nor '

The other point is the error TypeError: listdir() takes no keyword arguments
so why dont try:

for fileName in filter(os.path.isfile, os.listdir(direc))

instead of

for fileName in filter(os.path.isfile, os.listdir(path=direc))


来源:https://stackoverflow.com/questions/30787401/double-backslash-python-os-path-abspath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!