("Duh! Code would be good," says newbie to himself.)<br><br>Here's an example from django which I am using, but I asked on this list since it seems more related to python than the web framework:<br><br>class Contact(models.Model):<br>
first_name = models.CharField(max_length=30, blank=True)<br> last_name = models.CharField(max_length=30, blank=True)<br> email = models.EmailField(blank=True)<br> phone = models.PhoneNumberField()<br><br> def __unicode__(self):<br>
l=[self.first_name, self.last_name, self.email, self.phone]<br> res=[]<br> <br> for x in l:<br> if x != '':<br> res.append(x)<br> <br> return ';'.join(res)<br>
<br>Thanks!<br>Don<br><br><br><div class="gmail_quote">On Tue, Jul 8, 2008 at 11:56 AM, Kent Johnson <<a href="mailto:kent37@tds.net">kent37@tds.net</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">On Tue, Jul 8, 2008 at 9:14 AM, Don Jennings <<a href="mailto:dfjennings@gmail.com">dfjennings@gmail.com</a>> wrote:<br>
> Hi, folks.<br>
><br>
> From within a class, I want to return a string with data from non-empty<br>
> variables in a class.<br>
><br>
> I could create a list of all the variables and then iterate over them,<br>
> dropping the ones which are empty, then join() and return them; however, I<br>
> am guessing there is another way to get that list of variables or to<br>
> accomplish my goal. Suggestions?<br>
<br>
</div></div>It would help to see code that works according to your suggestion.<br>
<br>
Where do the variables come from? Do you mean a list of all the<br>
attributes in an instance of a class? A list comprehension is often<br>
useful for creating a filtered list but I don't know if it will work<br>
for you without understanding better what you want to do.<br>
<font color="#888888"><br>
Kent<br>
</font></blockquote></div><br>