Code - what could be done better?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Mon May 11 11:40:03 CEST 2009


Florian Wollenschein a écrit :
> Hi all,
> 
> here's the main code of thc, my txt to html converter. Since I'm a 
> beginner it is far, far, faaaaaaar away from perfect or even good :-)
> What could be done better?
> 
(snip code)

1/ decouple the text => html conversion part from your (or any other) GUI

2/ decouple the text => html conversion part from files handling (hint: 
given your code, any object having a 'write' method should do - IOW, the 
conversion code just a need an object with a "write(somestring)" method 
as argument, eventually defaulting to sys.stdout.

3/ write tags in lowercase, and get rid from the 'bgcolor' attribute in 
<body>

4/ or even better, use a templating system, to avoid hardcoding html in 
your code

Also an FWIW, there are quite a few 'simple markup' text format 
(textile, markdown, ReST, various wiki idioms etc). You may want to be 
able to use them too.

My 2 cents.





More information about the Python-list mailing list