Bruno Desthuilliers wrote:
MRAB a écrit :
On Oct 19, 5:47 pm, Bruno Desthuilliers
<[EMAIL PROTECTED]> wrote:
Pat a écrit :
(snip)
ip = ip[ :-1 ]
ip =+ '9'
or:

ip = ip[:-1]+"9"

(snip)
 >>> re.sub(r'^(((\d+)\.){3})\d+$', "\g<1>9", "192.168.1.1")
'192.168.1.9'

re.sub(r'^(((\d+)\.){3})\d+$', "\g<1>9", "192.168.1.100")
'192.168.1.9'

The regular expression changes the last sequence of digits to
"9" ("192.168.1.100" => "192.168.1.9") but the other code replaces the
last digit ("192.168.1.100" => "192.168.1.109").

Mmm - yes, true.

ip = ".".join(ip.split('.')[0:3] + ['9'])

As I first stated, in my very particular case, I knew that the last octet was always going to be a single digit.

But I did learn a lot from everyone else's posts for the more generic cases. thx!
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to