(Python) Issues with directories that have special characters
- 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:开发者_如何学Python" . 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()
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()
精彩评论