string compare question.Please Help!!!
shiver at yubc.net
Tue Dec 25 06:47:06 CET 2001
If you ar trying to compare strings as if they are numbers, you cant!
because when comparing strings, comparation begins from first characters of both strings and continues until ascii values are diferent, like sorting of filenames...
So '1' is equal to '1', '0' is equal to '0', '.' is equal to '.' but '6' has greater ascii than '2', and cmd() returns 1.
In the same way '2' is greater than '100'.
This should work
#split string into four substrings
ip1,ip2=ip1.split( '.'),ip2.split( '.')
#convert strings into numbers
ip1,ip2=[long(elem) for elem in ip1],[long(elem) for elem in ip2]
for n in range(4):
true should now be -1
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list