[Tutor] string formatting question

Alan Gauld alan.gauld at freenet.co.uk
Fri Apr 7 20:10:43 CEST 2006


> My problem now is how do I construct the replace
> statement?
> twork = m_sock.sub('\1 %s \2 %s', % port_num % proto,
> twork)

The format operator takes a tuple:

twork = m_sock.sub('\1 %s \2 %s' % (port_num, proto), twork)

So I  removed the comma after the string, used a single percent 
operator and I put the two variables in a tuple

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list