我是python新手,使用del
函数从列表中删除一些元素时遇到了困难。我向它传递一个包含多行的简单文本文件,使用splitlines()
创建一个行列表,然后尝试使用del
删除的前几个元素。在
但当我运行它时,它只是打印出列表而不删除行。但是我可以使用del inputfile[:]
删除所有内容。它没有出错,我有点卡住了。在
class Zero_Check(object):
def __init__(self):
self.path2file='C:\File2check\Output.txt'
def Parser(self):
print('parser')
inputfile = open(self.path2file).read().splitlines()
del inputfile[4]
print(inputfile)
#for line in inputfile:
# print(line)
if __name__=='__main__':
check=Zero_Check().Parser()
驱动器C中的卷是OSDisk 卷序列号为F0A9-9FB7
C:\File2check目录
2015年10月8日16:36。在
2015年10月8日16:36。。在
2015年10月8日16:28 0 1.txt
2015年10月8日16:28 0 10.txt
2015年10月8日16:28 0 11.txt
2015年10月8日16:31 241184 12.txt
2015年10月8日16:31 241184 13.txt
2015年10月8日16:31 241184 14.txt
2015年10月8日16:31 241184 15.txt
。。。在
输出-
^{pr2}$
不需要为简单操作创建类
相关问题 更多 >
编程相关推荐