Jul-21-2020, 04:32 AM
Hey all. I have a test file called beta.txt which has the following data:
I wish to save the value of frequency in a variable such that whenever I run the following command:
The value of the frequency stored in the variable is placed in place of 944.2M.
The values of the variable may change after ever while and I want to generate a code that can keep on automatically updating the value.
Ive tried initially by reading the test file and then splitting it.
Thanks
ARFCN: 990, Freq: 928.2M, CID: 667, LAC: 1007, MCC: 410, MNC: 3, Pwr: -30
I wish to save the value of frequency in a variable such that whenever I run the following command:
grgsm_livemon_headless -f 944.2M
The value of the frequency stored in the variable is placed in place of 944.2M.
The values of the variable may change after ever while and I want to generate a code that can keep on automatically updating the value.
Ive tried initially by reading the test file and then splitting it.
beta = open('beta.txt', 'rt') betalines = beta.readlines() x = print(betalines) y = x.split() print(y)However this always returns the following error:
Error:['ARFCN: 990, Freq: 928.2M, CID: 667, LAC: 1007, MCC: 410, MNC: 3, Pwr: -27\n']
Traceback (most recent call last):
File "example.py", line 34, in <module>
y = x.split()
AttributeError: 'NoneType' object has no attribute 'split'
I then also tried to store the line in a variable but that is not working either.mylines = [] with open ('beta.txt', 'rt') as myfile: for myline in myfile: mylines.append(myline) print(mylines)The list of individual words in the test file can be made by using the following code:
with open('beta.txt','r') as f: for line in f: for word in line.split(): print(word)But I dont know how to proceed further so that the second word of the list is always stored in a variable, say x, and that value of x can be added in the headless livemon formula.
Thanks