By PEP 8,
getInternetSpeed()
should beget_internet_speed()
. The function should probably accept a parameter for the URL to test. Furthermore, if the function is named "getSomething", I would expect it to return a value rather than print its result.For filename manipulation, use the
os.path
module.Avoid redefining variables, especially in a way that changes their type:
x = urllib2.urlopen('https://google.com') … x = x.read()
x
is a very poor variable name, by the way. I suggestreq
.open()
should almost always be used in the context of awith
block, so that the closure will be handled correctly for you:forwith open(os.path.join(temp_dir, 'TEMP.txt'), 'w') as f: f.write(x)
To generate temporary files, use the
tempfile
library to guarantee that you will not overwrite an existing file.
Changed "for" to "with" in the last section