Archive for the 'Python' Category


Python compile

Aug 01, 2014 in Python


python -m py_compile

Basic threading in python ..

Oct 20, 2010 in Python

The “main” script:

import threading
import someclass

csc = someclass.SomeClass()
csc_thread = threading.Thread(,args=())

The class used to run in a thread:

class SomeClass:
    def __init__(self):
        print "init"

    def run(self):
        # import pdb
        # pdb.set_trace() # trigger debugger
        for ix in range(1,10):
            print "run %d" % ix

To run it:

python [-m pdb]

Python dynamic class loading ..

Oct 16, 2010 in Python

File “” :

# file:

mod_name = "pkg.mod_loadee"
# Get module object (class is stored in a module)
mod_obj = __import__(mod_name, globals(), locals(), [''])

print ">> %s" % mod_obj

# Get class
class_obj = mod_obj.getClass()

print ">> %s" % class_obj

# Create instance from class object
class_inst = class_obj()

# invoke method

in folder “pkg”, make file “” :

class Loadee:
    def __init__(self):
        print "Loadee.init"
    def testme(self):
        print "Loadee.testme"

def getClass():
    return Loadee

run it:


do not forget the “./pkg/” to make the folder a package .