try:
print(filePath)
my_file = Path(filePath)
except ValueError:
print ValueError
试图运行该代码使用路径(文件)不断抛出的错误:不能没有抛出异常
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 26: ordinal not in range(128)
吹它的值是: Kellyanne Conway: Giuliani’s Withdrawal From Consideration A ‘Mutual Decision’ | MTP Daily | MSNBC.opus
我试着用ascii和unicode编码这个字符串,但它没有奏效。如何检查文件是否正确存在,谢谢。
什么是'Path'? – TigerhawkT3
'from pathlib import Path' – Antoine
Python 2或Python 3?它很重要。请参阅http://stackoverflow.com/questions/33938079/why-python2-and-python3-treat-same-windows-directory-differently和https://pypi.python.org/pypi/pathlib/(搜索“ASCII “) –