Python - List and Loop in one def

Posted by Dunwitch on Stack Overflow See other posts from Stack Overflow or by Dunwitch
Published on 2010-03-31T05:17:59Z Indexed on 2010/03/31 5:23 UTC
Read the original article Hit count: 219

Filed under:

I'm trying to get the def wfsc_pod1 and wfsc_ip into the same def. I'm not quite sure how to approach the problem. I want wfsc_pod1 to display all the information for name, subnet and gateway. Then wfsc_ip shows the ip addresses below it. I also get a None value when I run it as it. Not sure why. Anything more pythonic is more appreciated.

class OutageAddress:
    subnet = ["255.255.255.0", "255.255.255.1"]

    # Gateway order is matched with names
    gateway = ["192.168.1.1", "192.168.1.2", "192.168.1.3", "192.168.1.4",
                "192.168.1.5", "192.168.1.6", "192.168.1.7", "192.168.1.8",
                "192.168.1.9"]

    name = ["LOC1", "LOC2", "LOC3", "LOC4",
                "LOC5", "LOC6", "LOC7", "LOC8",
                "LOC9"]

    def wfsc_pod1(self):
        wfsc_1 = "%s\t %s\t %s\t" % (network.name[0],network.subnet[0],network.gateway[0])
        return wfsc_1

    def wfsc_ip(self):
        for ip in range(100,110):
            ip = "192.168.1."+str(ip)
            print ip

network = OutageAddress()
print network.wfsc_pod1()
print network.wfsc_ip()

© Stack Overflow or respective owner

Related posts about python