![]() |
read the first line in my script - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- 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 = '0.0.0.0' # 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)) s.listen() while True: if stop_threads: break 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: try: data = conn.recv(1024) if not data: break data_str = data.decode('utf-8') conn.close() #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. |