在运行一个小脚本时,脚本从一文本文件读取数据,事实上这个文件只有一行'count:2',并取到这个2,将其转成数字。但运行,总是报错。
代码如下:
1 with open('count.txt', 'r') as file: 2 if not file.readline(): 3 pass 4 else: 5 name, count = file.readline().split(':') 6 count = int(count)
在运行一个小脚本时,脚本从一文本文件读取数据,事实上这个文件只有一行'count:2',并取到这个2,将其转成数字。但运行,总是报错。
代码如下:
1 with open('count.txt', 'r') as file: 2 if not file.readline(): 3 pass 4 else: 5 name, count = file.readline().split(':') 6 count = int(count)
相关文章: