Python Forum
read the first line in my script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read the first line in my script
could someone help me write the proper code for reading the first line of a text file in c:\desktop\ptyhon\log.txt
here is the partial code that should be relevant to my question
def thread_loop():
    secretcode = "oaixxxxxxxxxxxxjxjxjxjxj"
    HOST = ''  # Standard loopback interface address (localhost)
    PORT = 58900        # Port to listen on (non-privileged ports are > 1023)

    log_path = os.path.dirname(os.path.realpath(__file__)) + "\log.txt"

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind((HOST, PORT))
        while True:

            if stop_threads: 
            conn, addr = s.accept()
            with conn:
                conn.sendall(str.encode('test_right_here'))  ######right here is where i want to read the first line from c:\desktop\log.txt
                while True:
                        data = conn.recv(1024)
                        if not data:
                        data_str = data.decode('utf-8')

#more script below..but too long to paste
FYI: Code windows are scrolled when too large to display at once, so you only have to worry that a script is too large when very large.

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to skip to a different line while importing a different script kat_gamer 2 658 Feb-03-2021, 04:10 AM
Last Post: deanhystad
  Read characters of line and return positions Gizzmo28 2 697 Nov-04-2020, 09:27 AM
Last Post: perfringo
  Read/Sort Large text file avoiding line-by-line read using mmep or hdf5 Robotguy 0 781 Jul-22-2020, 08:11 PM
Last Post: Robotguy
  Python: Automated Script to Read Multiple Files in Respective Matrices Robotguy 7 1,806 Jul-03-2020, 01:34 AM
Last Post: bowlofred
  Make the script read from any directory falahfakhri 2 951 Jun-15-2020, 02:18 PM
Last Post: falahfakhri
  Read a CSV file only from the 4th line/row asaforen7 8 1,903 Apr-16-2020, 01:49 AM
Last Post: Larz60+
  Read all csv files, and store the last line from each folder SriRajesh 4 3,715 Jan-17-2020, 12:13 AM
Last Post: SriRajesh
  How to read text file line by line SriRajesh 1 904 Nov-05-2019, 01:51 PM
Last Post: snippsat
  Read each line, replace string and save into a new file igormonteiro 2 1,661 Sep-15-2019, 01:24 PM
Last Post: buran
  When I read csv file i am getting b'Skipping line messages GuJu 4 5,994 Mar-07-2019, 11:47 AM
Last Post: GuJu

Forum Jump:

User Panel Messages

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