[Tutor] Re: quicker .strip?

Andrei project5 at redrival.net
Fri Jan 9 15:05:58 EST 2004

firephreek wrote on Fri, 9 Jan 2004 12:22:41 -0700:

> Hey, I'm brand spanking new to python, but I'm loving it.  I've begun
> writing my first program that will run as a temperature
> monitor/recorder.  I'm keeping track of unit IP's in a mysql database,
> and I've written a function to pull them out, problem is when I retrieve
> my 'list' of IP's from the databse, I get the info as a list, with each
> IP surrounded by ( and "  i.e. ((""),(""))  and I'm
> using strip() several times to get rid of the excess so that I can
> re-use the IP address when gathering my data.  Here's the code, I hope
> this all makes sense.  

I'm not sure I understand it correctly. Is ip a string? If it doesn't, my
reply won't make sense :).

Now that string looks just like Python code, doesn't it? If you just eval()
such a structure, it should automatically be turned into a tuple of tuples
in one line of code.

> I'm wondering if there's any functions/methods that will strip the info

The other solution is to use split() to split at '"),("' - this will split
all but the first and last IP in the resulting list. Then strip the leading
'(("' of the first IP and the trailing '"))' in the last IP of the
resulting list. It's a few extra lines of code.

> in fewer lines.  Or if there's another way of retrieving my information

I don't know more about this, but the options above should be enough even
if there is no smarter way of getting the data.



Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.

More information about the Tutor mailing list