python - str 不是可调用对象 python
问题描述
我有点好奇为什么我的代码会导致这个错误?
有人可以向我展示一些见解作为解决此问题的方法以及提高它的原因吗?
错误:
chunk += " " (16 - len(chunk) % 16)
TypeError: 'str' object is not callable
我的代码:
def upload(item):
with open(item, "rb") as fp:
while True:
chunk = fp.read(64*1024)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += " " (16 - len(chunk) % 16)
self.s.send(encrypt(self.key, chunk, self.iv))
self.s.send("DONE")
self.update()
解决方案
更改chunk += " " (16 - len(chunk) % 16)
为:
chunk += " " * (16 - len(chunk) % 16)
如果你什么都不放在那里,这意味着它" "
是可调用的,你正试图用16 - len(chunk) % 16
参数调用它。
推荐阅读
- php - 在刽子手游戏中存储所有猜测的字母
- azure - 没有开发人员门户的 Azure API 管理
- google-apps-script - 如何返回内置 Google 电子表格函数可以使用的字符串
- r - Ubuntu 18.04 RJDBC:到 oracle 的 JDBC 连接挂起没有响应
- ios - 将 Xcode 从 7 升级到 10 后 popoverController 不显示
- android - 将 2 个视图与 ConstraintLayout 并排放置
- video - SharePoint Online 是否支持 .MOV 视频文件
- git - 如何从分叉仓库获取远程分支到本地,并且当前从哪个分支推送的分叉仓库不存在
- php - 我想通过 JSON 使用 Ajax 从函数发送数组
- c# - 正则表达式验证花费太长时间 c#