Advanced read in a TXT file

Work data in a TXT file according the line number

You can grab data in a TXT file according the line number, or counting a number of lines before or after a specific string.

[code]file = open('C:/Users/Georges/Downloads/MyFile.txt', 'r')
lines = file.readlines()

listSubject = []
listFirstname = []

for num, x in enumerate(lines):
if x.startswith('Subject:\t'):
listSubject.append(x)
listFirstname.append(lines[num+6])

MergeLists = list(zip(listSubject, listFirstname))

df = pd.DataFrame(MergeLists, columns=['field Subject', 'field Firstname'])[/code]

Get encoding of a file

[code]from chardet import detect

def get_encoding_type(file):
with open(file, 'rb') as f:
rawdata = f.read()
return detect(rawdata)['encoding']

from_codec = get_encoding_type(MyFile)

print('from_codec')
print(from_codec)[/code]