i don't understand this code.what is happening where does socket and a come from.What means by a.startswith?
how does python understands arguments within square brackets like from the function defined below:
get_protnumber('AF_')[2]
the result is AF_INET
i will be grateful if someone guides me step by step
how does python understands arguments within square brackets like from the function defined below:
get_protnumber('AF_')[2]
the result is AF_INET
i will be grateful if someone guides me step by step
import socket def get_protnumber(prefix): return dict( (getattr(socket, a), a) for a in dir(socket) if a.startswith(prefix)) proto_fam = get_protnumber('AF_') types = get_protnumber('SOCK_') protocols = get_protnumber('IPROTO_') for res in socket.getaddrinfo('www.thapar.edu', 'http'): family, socktype, proto, canonname, sockaddr = res print 'Family :', proto_fam[family] print 'Type :', types[socktype] print 'Protocol :', protocols[proto] print 'Canonical name :', canonname print 'Socket address :', sockaddr