Python2Html

by jesse in ,


Did a little digging based off of comments from my last post about pasting code (python) into blogger. I found: python2html - it had a bug on line 318 under py2.5 ("wU" needs \r linebreaks, not \n). Otherwise, it worked beautifully. Let's give it a try on a snippet I snagged that emulates java's "synchronized" keyword:

  ''' Synchronization module. Emulates Java's 'synchronized' keyword. Derived from Bruce Eckel's code ''' import threading  class Synchronization:     def __init__(self):         self.mutex = threading.RLock()  def synchronized(method):     def func(*args,**kargs):         self = args[0]         self.mutex.acquire()          try:             return apply(method,args)         finally:             self.mutex.release()     return func  def synchronize(victim,names=0;">None):     'Synchronizes specified (all) methods in a given class'          if type(names)==str:    names = names.split()     for (name,val) in victim.__dict__.items():         if callable(val) and name != 'r: #006000;">__init__' and (names == None 04000;">or name in names):             #print "synchronizing",name             victim.__dict__[name] = synchronized(val)