Python2Html
October 10th, 2006 Posted in Programming, Python
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)


October 10th, 2006 at 7:12 pm
Hi Jesse, I’ve uploaded two screenshots Firefox 1.5.0.7 800×600 and IE 6.0 800×600.
Looks good. How about some tweaking regarding line wrapping (FF would look perfect) and/or use of horizontal space for code? It might be interesting to use a lighter background for colored code. Both would be addressed by something like pre {background:#f9f9ef; overflow:auto;} in your CSS (FF likes it, couldn’t test with IE).
And now, sheer-overkill-besides-it-already-works-ly, have you looked into SilverCity, Highlight, GNU Source-highlight and this alternative Python2HTML? :)
Cheers,
Daniel
October 11th, 2006 at 5:11 am
It may not be an issue for you but the code fragment doesn’t format properly with Bloglines:
def synchronize(victim,names=
0;”>
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;”>
r: #006000;”>__init__’ and (names == None
04000;”>
04000;”>or name in names):
#print “synchronizing”,name
victim.__dict__[name] = synchronized(val)