You are receiving that AttributeError
because the IpRangeList
object doesn't have an append
method defined. Plus, internally it defines the IP listing as a tuple which you can't append to.
What you can do however is create a complete list of the IP ranges you want and then create the IpRangeList
from that using *args
syntax to unpack the list into the function call, like so:
intranetlist = None
if os.path.isfile("/tmp/internal.list"):
fp = open("/tmp/internal.list", 'r')
intranetlist = IpRangeList(*[line.strip() for line in fp])
print intranetlist , len(intranetlist)
fp.close()
return intranetlist
As for appending to an already existing IpRangeList
, that won't be possible without changing it, nor does it look like you can easily access the list of IPs once you've created an IpRangeList
. So I'd suggest creating a basic Python list and creating the IpRangeList
at the last possible moment, because they are effectively immutable.