我无法让python读取特定的行.我正在做的是这样的事情:
lines of data not needed
lines of data not needed
lines of data not needed
--------------------------------------
***** REPORT 1 *****
--------------------------------------
[key] lines of interest are here
[key] lines of interest are here
[key] lines of interest are here
[key] lines of interest are here
[key] lines of interest are here #This can also be the EOF
--------------------------------------
***** REPORT 2 *****
--------------------------------------
lines of data not needed
lines of data not needed
lines of data not needed #Or …Run Code Online (Sandbox Code Playgroud) 我在某个字段对文本文件中的数据进行排序时遇到了一些麻烦.可能会在以后的多个领域..txt是几千行代码.我是python的新手,所以我的代码可能有点乱.例如,这是我将读取的文本文件:
stuff
123 1200 id-aaaa stuart@test.com
322 1812 id-wwww machine-switch@test.com
839 1750 id-wwww gary2-da@test.com
500 0545 id-aaaa abc123@test.com
525 1322 id-bbbb zyx321@test.com
Run Code Online (Sandbox Code Playgroud)
我的代码到目前为止如下:
filelist = open("info.txt").readlines()
splitlist = list()
class data:
def __init__(self, eventName, time, identity, domain):
self.evenName = eventName
self.time = time
self.identity = identity
self.domain = domain
for line in filelist:
filelist = list.split(', ')
splitlist.append(filelist)
for column in splitlist:
if (len(column) > 1): #to skip the first line
eventName = column[0].strip()
time = column[1].strip()
identity = column[2].strip() …Run Code Online (Sandbox Code Playgroud) 我认为表达问题的最佳方式是展示一个例子:
我说有一个十六进制数字2f.我想取这个十六进制数,然后在第五位加一个'9',然后是零.所以在这种情况下我想要 9002f.从这里我将把它转换回十进制.
我认为最好的方法是使用列表并列出['9','0','0','0','0']一个列表['2','f']以及以某种方式覆盖9000列表.
你们有什么感想?