首页 > 解决方案 > 使用 int() 错误

问题描述

谁能看到这段代码有什么问题:

offset = int((round((width - resize_width) / 2)), int(round((height - resize_height) / 2)))

这是我的错误信息:

TypeError: int() can't convert non-string with explicit base

谢谢,路易斯

标签: pythonint

解决方案


看看你的括号位置:

offset = int(
              ( round((width - resize_width) / 2) ),
              int( round((height - resize_height) / 2) )
            )

您的外部调用int有两个参数。您已将第二个int(round(...值作为基本参数传递。也许你想要点坐标?

offset = (int(round((width  - resize_width ) / 2)),
          int(round((height - resize_height) / 2))
         )

推荐阅读