Question : global name 'do_traceroute' is not defined?

I got the error message:  "NameError: global name 'do_traceroute' is not defined". Can anyone help me find what is wrong with my python code below?

------------------------------------------------------------------------------------------------------------------------------
import thread
import os

class Connecter:

... ...

    def do_traceroute():
        os.system('traceroute www.google.com')

        ... ...

    def got_message(self, connection, message):
 
        ... ...

            print 'Here is a test!'
            thread.start_new(do_traceroute, ())

        ... ...


Answer : global name 'do_traceroute' is not defined?

Because do_traceroute() is a method of your class, you need to say:

1:
2:
3:
def got_message(self, connection, message):
    ...
    thread.start_new(self.do_traceroute, ())
Open in New Window Select All
Random Solutions  
 
programming4us programming4us