0

I am trying to put together some simple code to refresh a speedtest website every 15 minutes and save the results.

I am trying to add in a simple variable output to keep track of the number of entries, but it keeps throwing up an error.

import sched, time, webbrowser

global n
n = 0

s = sched.scheduler(time.time, time.sleep)

def timesup(sc):
    n = n + 1
    print "This is run number ", n
    handle = webbrowser.get()
    handle.open('http://www.speedtest.com', new=0)
    sc.enter(10, 1, timesup, (sc,))

s.enter(10, 1, timesup, (s,))
s.run()

Any comments/suggestions would be appreciated.

  • 2
    Regardless of what the error is - you'll want to add `global n` within the function as well to tell Python to use the global version of `n` inside that function rather than creating a local version. (E.g. http://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them) – Amber Jun 24 '13 at 05:47
  • Thanks Amber, that solved the issue. – user2515048 Jun 24 '13 at 06:05

0 Answers0