#Server Side HTML SITE maker using Dictionary hash table as source DB for an SVG based webdesign. class htmlMaker: def __init__(self, domType='xstrict', cssType='internal', svgInBody='no'): self.db={} if domType=='xstrict': self.db['DOM']='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' elif domType=='xtrans': self.db['DOM']='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' elif domType=='html5': self.db['DOM']='<!DOCTYPE html>' else: print('Error: functioncal "domType" can only be: "xtrict", "xtrans" or "html5"') print('Defaulting to XHTML 1.0 STRICT - "xstrict"') self.db['html']='<html>' self.db['head']='<head>' if cssType=='internal': self.db['style']='<style>' elif cssType=='file': self.db['style']='<link rel="stylesheet" type="text/css" href="mystyle.css" />' else: print ('Error: function "cssType" must be set to either "inline" or "file". Defaulting to "inline".') self.db['style_close']='</style>' self.db['title']='<title>' self.db['tille_close']='</titles>' self.db['head_close']='</head>' self.db['body']='<body>' if svgInBody=='yes': self.db['svg']='<svg><?xml version="1.0" encoding="UTF-8"?>' self.db['svg_close']='</svg>' elif svgInBody=='no': self.db['svg']=' ' else: print ('Error: function call "svgInBody" requires "yes" or "no" boolean. Defaulting to "no"') self.db['svg']=' ' self.db['body_close']='</body>' self.db['</html>'] print ('The Following HTML Hashes are complete:') print (self.db) def htmlTester(self): print('Making Test HTML...') self.db['testText']='<h1>TESTING...</h1><br /><p>If you can read this the test was successful!</p>' #with output_file as open ('tester.html','w'): print self.db.get('DOM')+self.db.get('html')+self.db.get('head')+self.db.get('style')+self.db.get('style_close')+self.db.get('title')+self.db.get('title_close)'+self.db.get('head_close')+self.db.get('body')+self.db.get('testText')+self.db.get('body_close')+self.db.get('html_close') aPAGE=htmlMaker() aPAGE.htmlTester()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question