Dumb*ss newbie Q

2005-03-27 Thread Captain Dondo
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 " " + self.title + ""

#
# 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:


Fate_is_the_Hunter

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 [EMAIL PROTECTED] 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb*ss newbie Q

2005-03-27 Thread Jp Calderone
On Sun, 27 Mar 2005 17:06:05 -0800, Captain Dondo <[EMAIL PROTECTED]> wrote:
> [snip]
> 
> def url (self):
> self.url = ...
> 
> def thumb (self):
> self.thumb = ...
> 
> [snip]
> 
> The problem is that m.html in the test section fails with 
> 
> TypeError: cannot concatenate 'str' and 'instancemethod' objects
> 
> [snip]

Notice that you have a method named "url" as well as an attribute named 
"url".  You have the same problem for "thumb".  These methods and attributes 
are in collision with each other.  When you try to look up the attribute, you 
might get the method.  When you try to look up the method, you might get the 
attribute.  It is deterministic, but depends on the order in which you do 
things, and highly confusing no matter what.  Avoid naming attributes and 
methods the same thing.

  Jp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb*ss newbie Q

2005-03-27 Thread Captain Dondo
On Mon, 28 Mar 2005 01:15:34 +, Jp Calderone wrote:
> 
>  Notice that you have a method named "url" as well as an attribute
>  named "url".  You have the same problem for "thumb".  These methods
>  and attributes are in collision with each other.  When you try to
>  look up the attribute, you might get the method.  When you try to
>  look up the method, you might get the attribute.  It is
>  deterministic, but depends on the order in which you do things, and
>  highly confusing no matter what.  Avoid naming attributes and
>  methods the same thing.

DUH!!!

works like a charm

Thanks!

-- 

use munged address above to email me
SpamTrap [EMAIL PROTECTED] 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb*ss newbie Q

2005-03-28 Thread Larry Bates
Others have answered your specific question, I thought I
would add some suggestions (not tested):

1) You don't need a separate set_title method.  You can
change the title attribute at any time by just saying
m.title="new title".  No method is required unless you
need to do some pre/post processing.

m.title="anything you want"

2) To get class to prepare its output, just insert a
__str__ method like following:

def __str__(self):
return ' http://starship.python.net/crew/friedrich/HTMLgen/html/main.html

(I actually stole the idea of using the the __str__ method to
generate the output from this module).

Hope information helps.

Larry Bates

Captain Dondo wrote:
> 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, title="", audience="", driver=""):
>   #
>   # 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 "   self.driver + "> " + self.title + ""
> 
> #
> # 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:
> 
>  href=avi://kids/Fate_is_the_Hunter/X=hermes.seiner.lan:xv,athena.seiner.lan:xmga,default:x11;console=vesa>
> Fate_is_the_Hunter
> 
> 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
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dumb*ss newbie Q

2005-03-29 Thread Captain Dondo
On Mon, 28 Mar 2005 08:42:22 -0600, Larry Bates wrote:

> Others have answered your specific question, I thought I
> would add some suggestions (not tested):
> 
> 1) You don't need a separate set_title method.  You can
> change the title attribute at any time by just saying
> m.title="new title".  No method is required unless you
> need to do some pre/post processing.
> 
> m.title="anything you want"
> 
> 2) To get class to prepare its output, just insert a
> __str__ method like following:
> 
> def __str__(self):
> return 'driver="X=hermes.seiner.lan:xv,athena.seiner.lan:xmga," \
>  "default:x11;console=vesa")
> print m
> 
> 
> If you plan on doing a lot of this you may want to take a look
> at the htmlgen module at:
> 
> http://starship.python.net/crew/friedrich/HTMLgen/html/main.html
> 
> (I actually stole the idea of using the the __str__ method to
> generate the output from this module).
> 
> Hope information helps.

Thanks, it does.  I am trying to write a much simplified album -
 . The author has taken it in a
direction that is no longer useful to me and I am desparately incompetent
in perl  Python and I like each other, except that I don't have much
experience writing it from scratch

For now I am using this tutorial as a go-by:
, but I will check out
the link you provided.

--Yan

-- 

use munged address above to email me
SpamTrap [EMAIL PROTECTED] 

-- 
http://mail.python.org/mailman/listinfo/python-list


Use informative subject lines! (was Re: Dumb*ss newbie Q)

2005-03-27 Thread beliavsky
A subject line should say what the message is about, for example

"Create HTML tag using objects (newbie Q)"

and enable people who are not interested in or knowledgable about a
topic to skip it, while grabbing the attention of people who are
knowledgable/interested.

-- 
http://mail.python.org/mailman/listinfo/python-list