Nov-13-2021, 11:16 PM
I have this code:
and i'm trying to understand this line: f{len(msg):<10{HEADERSIZE}}
so i opened my ide and i did this:
>>> msg = 'Hello World!'
>>> len(msg)
12
>>> len(msg):<10
SyntaxError: invalid syntax
for me it's pretty much the same thing so... why doen't it work?
Plus, if you remove the string literal in line fourteen, doesn't give : msg = 22:<10 10 + msg???
I tried to find an explanation on the web, but to no avail...
Could someone explain what's going on?
Could someone explain?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import socket HEADERSIZE = 10 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((socket.gethostname(), 1234 )) s.listen( 5 ) while True : clientsocket, address = s.accept() print ( f "Connection from {address} has been established!" ) msg = "Welcome to the server!" msg = f '{len(msg):<10{HEADERSIZE}}' + msg clientsocket.send(bytes( "msg" , "utf-8" )) while True : time.sleep( 3 ) msg = f "The time is! {time.time()}" msg = f '{len(msg):<{HEADERSIZE}}' + msg clientsocket.send(bytes(msg, "utf-8" )) |
so i opened my ide and i did this:
>>> msg = 'Hello World!'
>>> len(msg)
12
>>> len(msg):<10
SyntaxError: invalid syntax
for me it's pretty much the same thing so... why doen't it work?
Plus, if you remove the string literal in line fourteen, doesn't give : msg = 22:<10 10 + msg???
I tried to find an explanation on the web, but to no avail...
Could someone explain what's going on?
Could someone explain?