Python Forum
How to extract a single word from a text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to extract a single word from a text file
#3
(Jul-21-2020, 07:02 AM)bowlofred Wrote: Your first error is because you've set "x" to be the return value of print(). print() has no return value, so "x" becomes None. What did you want x to be?

readlines() reads all the lines in the file. If you only have one line, you might prefer readline().

If you want to split the line (which was previously "betalines[0]"), you'd do betalines[0].split().

beta = open('beta.txt', 'rt')
betaline = beta.readline()
y = betaline.split()[3]
print(y)
Output:
928.2M,

Thankyou so much. I wanted to clarify one last thing though. My value is stored in the variable y. So now when I have to execute the python command:
grgsm_livemon_headless -f 944.2M
Can I simply replace the value of the frequency (in this example 944.2M) by y?
Thanks again.

edited: I tried again. the command doesnt pick up the value of y as a variable and returns the following error
Error:
grgsm_livemon_headless: error: option -f: invalid engineering notation value: 'y
Reply


Messages In This Thread
RE: How to extract a single word from a text file - by buttercup - Jul-21-2020, 08:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract substring from a string before a word !! evilcode1 3 532 Nov-08-2023, 12:18 AM
Last Post: evilcode1
  Replace a text/word in docx file using Python Devan 4 3,290 Oct-17-2023, 06:03 PM
Last Post: Devan
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 981 Jan-23-2023, 04:56 AM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,111 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  extract only text strip byte array Pir8Radio 7 2,921 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  python Multithreading on single file mg24 3 1,725 Nov-05-2022, 01:33 PM
Last Post: snippsat
  extract last word from path. mg24 4 1,736 Nov-01-2022, 10:55 AM
Last Post: carecavoador
  Extract only certain text which are needed Calli 26 5,843 Oct-10-2022, 03:58 PM
Last Post: deanhystad
  Create multiple/single csv file for each sql records mg24 6 1,384 Sep-29-2022, 08:06 AM
Last Post: buran
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,263 Jul-27-2022, 12:31 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020