Dumb*ss newbie Q

Captain Dondo yan at NsOeSiPnAeMr.com
Sun Mar 27 20:06:05 EST 2005


OK, I know this is covered somewhere in Python 101, but for the life of me
I cannot figure this out.  I really need a basic intro to Python book....

I am trying to do something very simple - create an HTML tag using objects:

class Movie:

    def __init__ (self, t="", a="", d=""):
	#
	# Create an instance of Movie
	#
	self.title = t
	self.audience = a
	self.driver = d

    def set_title (self, new_title):
	self.title = new_title

    def set_audience (self, audience):
	#
	# Only 3 valid values: kids, parents, guests
	#
	self.audience = audience	    

    def set_driver (self, new_driver):
	self.driver = new_driver

    def url (self):
	self.url = "avi://" + self.audience + "/" + self.title + "/" + self.driver

    def thumb (self):
	self.thumb = self.audience + "/tn/" + self.title + ".jpg"

    def html (self):
	print "<a href=avi://" + self.audience + "/" + self.title + "/" +
	self.driver + "> <img src=" + self.thumb + ">" + self.title + "</a>"

#
# Code to test this class
#
if __name__ == '__main__':
    print "**** Test 1 ****"
    m=Movie("Fate_is_the_Hunter")
    m.set_audience ("kids")
    m.set_title ("Fate_is_the_Hunter")
    m.set_driver ("X=hermes.seiner.lan:xv,athena.seiner.lan:xmga,default:x11;console=vesa")
    m.html ()
    print "*** Finish ***"

The problem is that m.html in the test section fails with 

TypeError: cannot concatenate 'str' and 'instancemethod' objects

I got it working once.  The output should be something like this:

<a
href=avi://kids/Fate_is_the_Hunter/X=hermes.seiner.lan:xv,athena.seiner.lan:xmga,default:x11;console=vesa>
<img src=kids/tn/Fate_is_the_Hunter.jpg>Fate_is_the_Hunter</a>

but then I made some minor edits and I can't get it to work again....

Where do I find documentation on Python classes?  Or how do I convert one
to the other?  Or, how do I get the above to work?  This is the first time
I've really tried to work with a class I've defined myself and I obviously
don't know what I am doing....

On a minor note, if you look at the audience method, I want to limit it to
3 values.  How do I do that?

TIA....

--Yan

-- 

use munged address above to email me
SpamTrap DoMeNow at seiner.com 




More information about the Python-list mailing list