Re: [Zope] dtml-in over the output from my method
- Original Message - From: Max M <[EMAIL PROTECTED]> To: Tim Hicks <[EMAIL PROTECTED]>; Zope@Zope. Org <[EMAIL PROTECTED]> Sent: Monday, November 06, 2000 9:48 PM Subject: RE: [Zope] dtml-in over the output from my method > > def list_messages(self): > > class msg: > def __init__(self, msgnum, msgfrom, msgsub): > self.msgnum = msgnum > self.msgfrom = msgfrom > self.msgsub = msgsub > > msgList = [] > lr = open(self.user_dir+'/msg_list', 'r') > spl = re.compile('\s\|\s') > for msg_line in lr.readline(): > num_from_sub = [] > num_from_sub = spl.split(msg_line, 2) > > # Oh no ... this wont cut it! > #self.msgnum = num_from_sub[0] > #self.msgfrom = 'This is from UNKNOWN' > #self.msgsub = 'My special subject' > #return self.msgnum, self.msgfrom, self.msgsub > > # Do it like this: > msgList.append(msg(num_from_sub[0],'This is from UNKNOWN', >'My special subject')) > return msgList > > Brilliant, it works a treat. Thanks very much. tim ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] dtml-in over the output from my method
The problem is the first time your for loop runs it will return to the dtml and will not run anymore. Rather build up a list, or list of objects inside your method and then return. Dtml-in needs to see a list. -- Andy McKay, Developer. ActiveState. - Original Message - From: "Tim Hicks" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, November 06, 2000 12:45 PM Subject: [Zope] dtml-in over the output from my method I am trying to create a zope product in python but have got stuck with using the dtml-in tag to iterate over a method (or is it a function? I get a little mixed up) of my class. Here is the method, def list_messages(self): lr = open(self.user_dir+'/msg_list', 'r') spl = re.compile('\s\|\s') for msg_line in lr.readline(): num_from_sub = [] num_from_sub = spl.split(msg_line, 2) print num_from_sub self.msgnum = num_from_sub[0] self.msgfrom = 'This is from UNKNOWN' self.msgsub = 'My special subject' return self.msgnum, self.msgfrom, self.msgsub And here is an extract from the dtml file that is supposed to display the output, &dtml-msgfrom; &dtml-msgsub; However, this does not produce the desired effect. I don't know if it is obvious from what I've written, but basically, the three variables (self.msgnum, self.msgfrom and self.msgsub) are supposed to be inserted into the appropriate place in the table, and then the 'for' statement re-executed (producing different values for the variables) with the subsequent values being inserted into the next line of the table etc... until there are no more lines to be read from lr. I'm not sure if that is clear or not, sorry. Obviously, this does not work as the dtml-in simply iterates over each of the returned variables (instead of over the for statement). I can't seem to make it do what I want. Does anyone have any ideas? Much obliged if you do. Cheers tim ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] dtml-in over the output from my method
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Tim Hicks >I am trying to create a zope product in python but have got stuck with using the >dtml-in tag to iterate over a method (or is it a function? I get a little mixed >up) of my class. Here is the method, def list_messages(self): msgList = [] lr = open(self.user_dir+'/msg_list', 'r') spl = re.compile('\s\|\s') for msg_line in lr.readline(): num_from_sub = [] num_from_sub = spl.split(msg_line, 2) print num_from_sub self.msgnum = num_from_sub[0] self.msgfrom = 'This is from UNKNOWN' self.msgsub = 'My special subject' return self.msgnum, self.msgfrom, self.msgsub return msgList The dtml-in does not call your method for every iteration, it just calls once and then expects a list in return. What you need to do is to create a method that returns a list of objects: def list_messages(self): class msg: def __init__(self, msgnum, msgfrom, msgsub): self.msgnum = msgnum self.msgfrom = msgfrom self.msgsub = msgsub msgList = [] lr = open(self.user_dir+'/msg_list', 'r') spl = re.compile('\s\|\s') for msg_line in lr.readline(): num_from_sub = [] num_from_sub = spl.split(msg_line, 2) # Oh no ... this wont cut it! #self.msgnum = num_from_sub[0] #self.msgfrom = 'This is from UNKNOWN' #self.msgsub = 'My special subject' #return self.msgnum, self.msgfrom, self.msgsub # Do it like this: msgList.append(msg(num_from_sub[0],'This is from UNKNOWN', 'My special subject')) return msgList ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )