[Tutor] quicker .strip?

firephreek firephreek at earthlink.net
Fri Jan 9 14:22:41 EST 2004


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. (("10.1.1.205"),("10.1.1.206"))  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.  
 
## Setup MySQL connection:
conn=MySQLdb.connect(host=SQLHOST, user=SQLUSER, db=SQLDATA
passwd=SQLPASS)    
cursor=conn.cursor()    ## Setup MySQL cursor
cursor.execute("SELECT * FROM ip")  ## My list of IP address where my
devices are located
ip=cursor.fetchall()
## At this point ip looks like this: (("10.1.1.205"),("10.1.1.206"))
for x in range(len(ip)):  
        alpha=IP_strip(str(ip[x])) 
        config=getConfig(alpha)  ##Custom function that uses httplib to
get a page from my device over the network.

def IP_strip(ip):
    alpha=string.strip(ip, ")")
    alpha=string.strip(alpha, "(")
    alpha=string.strip(alpha, ",")
    alpha=string.strip(alpha,"'")
    return alpha
 
I'm wondering if there's any functions/methods that will strip the info
in fewer lines.  Or if there's another way of retrieving my information
so that I won't have to strip it.
 
-Stryder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040109/77bec88b/attachment.html


More information about the Tutor mailing list