在文本fi中分隔字符串和数字

2024-09-30 14:35:08 发布

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

我有一个包含数字和字符串的文件,该文件如下所示:

你知道吗示例.txt你知道吗

100
no of benches = 40
no of lights=160
400
700

我尝试使用string.atoi来分隔数字,但未能获得输出。这是我的密码:

import string
file = open('sample.txt')
numbers = file.readline()
k= string.atoi(numbers)
print(k)

是否有任何特定的模块或命令来执行此任务?你知道吗


Tags: 文件ofno字符串importtxt密码示例