maco1717 maco1717 - 1 year ago 75
Python Question

Python print result several variables/function calls on same line with string

I'm trying to print time stamp and a socket peer name (IP address)...

I can't figure out how python syntax work. I've been trying different version but in essence what i've tried is something like this:

print time.strftime("%X") " - " socket.getpeername()

I want to print "time - IP address" from clients connecting to server...

How can I print two "variables" (result of a function calls) with a string in between.

any suggestions on how to implement this?

Answer Source
now  = time.strftime("%X")
peer = socket.getpeername()
print("{} - {}".format(now, peer))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download