So I'm having some trouble with these Python lists I am trying merge together. I am trying to write an algorithm to check if the machine is connected to the internet. So I ping different Google servers and if none of them responds I assume the machine is offline.
The script I am using to ping the servers is a rewrite I made of another script and it can be found here. The echo()
function sends one ping and returns either the response delay (in seconds) or None
if it fails. The recursive()
functions sends multiple pings and returns a list with the responses from echo()
(e.g. [0.054, 0.134, None, 0.037]
).
The recursive
function (short of docstring and some tired comments):
def recursive(dest_addr, count=4, timeout=1, verbose=False):
if verbose:
print("PING {} ; SEQUENCE {} ; TIMEOUT {}s".format(dest_addr, count, timeout))
nrc = 0
log = []
for i in xrange(count):
log.append(echo(dest_addr, timeout))
if verbose:
if log[-1] is None:
print("Echo Request Failed...")
nrc += 1
else:
print("Echo Received: sequence_id={} delay={} ms").format(i, round(log[-1]*1000, 3))
return log
So when I ping these servers, I get multiple lists of those, and attempt to merge them like so:
results = recursive("google.ca") # North America
results = results.extend(recursive("google.com.br")) # South America
Doing that renders me the following error:
AttributeError: 'NoneType' object has no attribute 'extend'
I would like to know why that is happening.
Thanks in advance.