问题
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