有没有一种方法可以让python读取行,只使用前10个字符,然后将它们赋给一个变量?
Remove_example= 'example'
Remove_at= '@'
#Remove_Agent='
filepath = 'Older WinCollect Agents on Version 728.txt'
with open(filepath) as fp:
line = fp.readline()
print(line[0][10])
cnt = 1
while line:
print("Line {}: {}".format(cnt, line.strip(),).replace(str(Remove_example),'').replace(str(Remove_at),''))
line = fp.readline()
cnt += 1我不想把静态删除行变量
发布于 2020-05-12 04:04:17
def get_line_fronts(filepath: str) -> list:
"""Get list of first 10 characters in each line in a file."""
line_fronts = []
with open(filepath, "r") as fh:
for line in fh:
line_fronts.append(line[:10])
return line_fronts
filepath = 'Older WinCollect Agents on Version 728.txt'
for line_front in get_line_fronts(filepath):
# do whateverhttps://stackoverflow.com/questions/61738104
复制相似问题