双反斜杠python os.path.abspath [英] double backslash python os.path.abspath

查看:64
本文介绍了双反斜杠python os.path.abspath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了路径

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

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

但是 direC:\\ 并向我发送下一个错误:

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

TypeError: listdir() takes no keyword arguments

当我打印 dire 以查看接下来打印的内容时:

when I print dire to see the content print next:

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

如何在 os.path.abspath(".") 中获取 \ 而不是 \\ ?

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

推荐答案

我假设 print 的意思是 repr.

I'm assuming that by print you mean repr.

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

请注意,打印时既没有双 \\ 也没有 '

另一点是错误 TypeError: listdir() 没有关键字参数
所以为什么不尝试:

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))

代替

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

这篇关于双反斜杠python os.path.abspath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆