python - 我不断收到 ValueError: invalid literal for int() with base 10: 错误。由于某种原因,无法将字符串转换为 int
问题描述
FILE_NAME = 'last_seen.txt'
def read_last_seen(FILE_NAME):
file_read = open(FILE_NAME, 'r')
last_seen_id = int(file_read.read().strip())
file_read.close()
return last_seen_id
id = read_last_seen(FILE_NAME)
print(id)
它说第 20 行有一个错误。我正在尝试为 twitter 提及编写代码,该代码由数字 id 标识。但是,我不断收到此错误。
解决方案
好的。这很尴尬。
经过几个小时的尝试,我删除了文本文件,创建了一个新文件。
不知何故,代码无法访问文本文件。所以,删除它并创建一个新的文本文件为我做了!
推荐阅读
- java - 在 JUnit 测试之前我应该如何启动服务器?
- sqlite - 涵盖精确匹配和小于/大于sqlite中查询的最佳索引
- angular - http获取请求的角度获取值选择菜单
- visual-studio-code - 两个项目的Vscode格式“保存时”不同
- wordpress - 使用图片作为联系表格 7 上的单选按钮,但未在邮件中接收图片
- java - 尝试针对 PostgreSQL 数据库为 Spring 开发设置 H2 数据库
- c++ - new int[100] 和 new int[100]() 之间的区别;
- c++ - opengl不填充多边形
- scala - 每组在 Spark-Scala 中查找百分位数
- vue.js - nuxtjs/google-tag-manager 仅在获得 cookie 同意后才添加谷歌分析