问题
- OS: Windows server 03
- Python ver: 2.7
For the code below, its runs fine when I substitute "fuchida@domain.com" with "fuchida". If I use the email format for directory name I get the following error "WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect:" . Please let me know what I can do to get this to work, my money is on the "@" symbol fudging things up but I do not know how to resolve it in python so far.
import os
def dirListing():
dirList = os.listdir("C:\\Program Files\home\Server\Logs\fuchida@domain.com")
for fname in dirList:
print fname
return
def main():
dirListing()
if __name__ == '__main__':main()
回答1:
I suspect problems with your \ as escape characters. Try this:
import os
def dirListing():
dirList = os.listdir(r"C:\\Program Files\home\Server\Logs\fuchida@domain.com")
for fname in dirList:
print fname
return
def main():
dirListing()
if __name__ == '__main__':main()
来源:https://stackoverflow.com/questions/7268618/python-issues-with-directories-that-have-special-characters