thc v0.3 - txt to html converter - better code?
Richard Brodie
R.Brodie at rl.ac.uk
Wed May 6 04:45:24 EDT 2009
"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
More information about the Python-list
mailing list