Python将txt文件内容转换成列表

2022-09-02 21:03:47 浏览数 (1)

方法一:

代码语言:javascript复制
# -*- coding:utf-8 -*-
f = open(r'ip.txt','r')
a = list(f)
print(a)
f.close()

方法二:

代码语言:javascript复制
# -*- coding:utf-8 -*-
f = open(r'ip.txt','r')
a=[i for i in f]
print(a)
f.close()

0 人点赞