seit kurzem beschäftige ich mich wieder mehr mit oop. und die new style klassen, die dookie uns erklärt hat sind ein scharfes ding. momentan habe ich einfach lust alles mögliche mit neuen und alten klassen auszuprobieren.
angefangen hat alles hier
http://python.sandtner.net/viewtopic.php?t=1466
ob die idee gut ist oder nicht, weiss ich net, auch kann ich eventuelle negative nebenwirkungen net abschätzen, aber funktionieren tut es:
Code: Alles auswählen
#!/usr/local/bin/python
from webtools import *
class Site_a:
content_type='''Content-Type: text/html
'''
general='''<html><head><title>crossoverguitar</title>
<link rel='stylesheet' type='text/css' href='../../crossover/sheet1.css'></head>
<body background='../../crossover/_themes/kopie-von-sumi-malerei/sumtextb.jpg'>
<div align='center'>'''
content='''<h2>Eine dynamisch erstellte Seite</h2>
<p><a href='http://localhost/crossover/'>...zur&ck zu Crossoverguitar</a></p>'''
end='''</div></div><p><br><hr color='#990000'>
<div align='center'>
<span class='copyright'>©right 2000 roga-verlag ---
<a href='mailto:rolandgall@weberanto.net' target='inhalt'>rolandgall@weberanto.net</a>
</span></div></p></body></html>'''
def __init__(self):
print self
def __str__(self):
site=self.content_type+self.general+self.div+self.content+self.end
return site
class ErrorSite_a(Site_a):
content='''<h2>%s</h2>
<p><a href='javascript:history.back()'>%s</a></p>'''
def __init__(self,errortype,link):
self.errortype=errortype
self.link=link
self.content=self.content%(self.errortype,self.link)
print self
class ConfirmationSite_b(Site_a):
content='''<h2>%s</h2>'''
def __init__(self,confirmation):
self.confirmation=confirmation
self.content=self.content%(self.confirmation)
print self
##
##for myclasses in (Site,ErrorSite):
## myclasses.divb='''<div style='width:555; margin-top:150px; margin-bottom:125px;'>'''
##
##for myclasses in (ConfirmationSite,TestSite):
## myclasses.divb='''<div style='width:555; margin-top:100px; margin-bottom:125px;'>'''
k=globals()
l=k.copy()
for i in l:
instance=l[i]
if i.endswith('Site_a'):
instance.div='''<div style='width:555; margin-top:150px; margin-bottom:125px;'>'''
if i.endswith('Site_b'):
instance.div='''<div style='width:555; margin-top:100px; margin-bottom:125px;'>'''
if __name__=='__main__':
## a=Site_a()
b=ErrorSite_a('Du bist zum Tode verurteilt!','...hier gehts zum Henker')
## c=ConfirmationSite_b('Danke f&r die tolle Klasse!')
dann dachte ich mi: ich lass den namenraum auslesen und such dann alle Seiten des Typs a und Typs b, das scheint mir leichter und angenehmer zu warten. ich brauche also nur nuch mir beim definieren überlegen, welcher typ die klasse werden soll.
was meint ihr dazu?
mfg
rolgal