PyPng:AttributeError:“module”对象没有属性“Writer”

2024-06-06 17:16:12 发布

您现在位置:Python中文网/ 问答频道 /正文

对Python有些陌生。尝试PyPNG(需要编写一些简单的PNG文件)。使用代码(几乎)与the documentation中的示例完全相同。在

import png

def main():
  f = open('ramp.png', 'wb')      # binary mode is important
  w = png.Writer(255, 1, greyscale=True)

  w.write(f, [range(256)])

  f.close()

if __name__ == "__main__":
  main()

尝试完全按照文档中的说明运行(没有添加main()命令)。在

当我运行时,我得到一个错误:

^{pr2}$

谷歌什么都不提供。请帮忙?在


Tags: 文件the代码import示例pngmaindef