Skip to main content
 首页 » 编程设计

python之Windows 文件名被破坏

2025年05月04日9dflying

我正在尝试使用 PIL Image 的 open 方法打开图像,但出现以下错误。

我已将图像存储在 C:\a.jpg 中。

>>> h1 = Image.open("C:\a.jpg").histogram() 
 
Traceback (most recent call last): 
  File "<pyshell#8>", line 1, in <module> 
    h1 = Image.open("C:\a.jpg").histogram() 
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 1952, in open 
    fp = __builtin__.open(fp, "rb") 
IOError: [Errno 22] invalid mode ('rb') or filename: 'C:\x07.jpg' 

请您参考如下方法:

你有转义字符的问题,使用@NelleshSharma 或的方法

Image.open(r'c:\a.jpg').histogram();