thc v0.3 - txt to html converter - better code?

Florian Wollenschein Florian.Wollenschein at FernUni-Hagen.de
Wed May 6 18:06:17 CEST 2009


Richard Brodie wrote:
> "Stefan Behnel" <stefan_ml at behnel.de> wrote in message 
> news:4a008996$0$31862$9b4e6d93 at newsspool3.arcor-online.net...
> 
>>    language_map = {'English': 'EN', 'Deutsch': 'DE'}
>>    strict_or_transitional = {True: 'Transitional', False: 'Strict'}
>>
>>    # this will raise a KeyError for unknown languages
>>    language = language_map[ self.cmboBoxLang.currentText() ]
>>
>>    # this assumes that isChecked() returns True or False
>>    spec = strict_or_transitional[self.rdioBtnTransitional.isChecked()]
>>
>>    doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 %s/%s">\n' % (
>>        spec, language)
> 
> Incidentally, the language in an HTML DOCTYPE refers to the language of the DTD, not
> the document. It's never correct to use //DE in an HTML page, unless you have a custom
> (German) DTD. So the code can be improved further by cutting that part out.
> 
>     strict_or_transitional = {True: 'Transitional', False: 'Strict'}
> 
>     # this assumes that isChecked() returns True or False
>     spec = strict_or_transitional[self.rdioBtnTransitional.isChecked()]
> 
>     doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 %s//EN">\n' % spec
> 
> 


Yes, that's true. I missed that. Thanks for the information.
And many thanks to Stefan.



More information about the Python-list mailing list