I have a following issue, there is a function to read a big file(few Mb), the content looks like:
0x05 0x00 0x00 0x00 0xCF 0x00 0x00 0x00 ; ..........
0xCF 0x00 0x00 0x00 0x22 0x00 0x00 0x00 ; ......"...
0x51 0x84 0x07 0x00 0x02 0x00 0x01 0x00 ; ..Q.......
My function has to read only the hex values, and to ignore ";" with following characters till the end of line.
Data from the first line what I need is
"0x05 0x00 0x00 0x00 0xCF 0x00 0x00 0x00 "
I tried two methods, one is with a separate file with this function
def ReadFileAsList(fileName):
fileName = "2Output.txt"
fileContentStr = ""
with open(fileName,'r') as f:
for line in f:
fileContentStr += line.split(';')[0]
fileContentList = fileContentStr.split()
return fileContentList
and the second method, when these line are directly in my main .py file
fileName = "2Output.txt"
fileContentStr = ""
with open(fileName,'r') as f:
for line in f:
fileContentStr += line.split(';')[0]
fileContentList = fileContentStr.split()
The second method is very fast, the first(with the separate function in a separate file) is very slow, what am I missing? Thanks for any hint