Python 3.x 如何将qr_码img导出到磁盘?

Python 3.x 如何将qr_码img导出到磁盘?,python-3.x,save,qr-code,Python 3.x,Save,Qr Code,我使用python包从url生成二维码图像: 如何将img以特定路径保存到磁盘 我试过: image_file = open(path_qr_code, 'w') image_file.write(img) image_file.close 但我得到: TypeError:写入参数必须是str,而不是PilImage 试试这个: img.save("img.png","PNG") 或使用路径: img.save(path_qr_code + "\\" + "imgtest.png","PNG

我使用python包从url生成二维码图像:

如何将img以特定路径保存到磁盘

我试过:

image_file = open(path_qr_code, 'w')
image_file.write(img)
image_file.close
但我得到:

TypeError:写入参数必须是str,而不是PilImage

试试这个:

img.save("img.png","PNG")
或使用路径:

img.save(path_qr_code + "\\" + "imgtest.png","PNG")
试试这个:

img.save("img.png","PNG")
或使用路径:

img.save(path_qr_code + "\\" + "imgtest.png","PNG")
TypeError:写入参数必须是str,而不是PilImage

这表示img有PilImage类型,然后您可以使用该方法保存它。比如说,

img.save(path_qr_code)
TypeError:写入参数必须是str,而不是PilImage

这表示img有PilImage类型,然后您可以使用该方法保存它。比如说,

img.save(path_qr_code)

提示:不是PIL映像,然后您可以搜索如何将PIL映像保存到磁盘。然后我发现这个提示:不是PIL映像,然后,您可以搜索如何将PIL映像保存到磁盘。然后,我使用pathlib或至少os.path.join发现了此问题。建议使用字符串连接来自动处理Linux/Windows路径问题/忘记/重复分隔符使用pathlib或至少os.path.join来处理字符串连接来自动处理Linux/Windows路径问题/忘记/重复分隔符