Python Forum
read the first line in my script - Printable Version

+- Python Forum (
+-- Forum: Python Coding (
+--- Forum: General Coding Help (
+--- Thread: read the first line in my script (/thread-30827.html)

read the first line in my script - chubbychub - Nov-08-2020

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

RE: read the first line in my script - Larz60+ - Nov-09-2020

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.