Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31314
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: What's the tidy/elegant way to protect this against null/empty parameters? |
| Date | 2012-10-15 11:45 -0400 |
| References | <1b8tk9-un9.ln1@chris.zbmc.eu> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2216.1350315959.27098.python-list@python.org> (permalink) |
On 10/15/2012 7:23 AM, tinnews@isbd.co.uk wrote:
> I want to fix an error in some code I have installed, however I don't
> really want to just bodge it.
>
> The function producing the error is:-
>
> def get_text(self, idx): # override !
> node = self.items[idx]
>
> a= [
> ", ".join(node.tags),
> node.comment,
> node.folderName,
> cd2rd(node.date),
> node.name,
> '[' + self.rating_stars[node.rating] + ']'
> ] [self.select]
>
> return a
>
>
> The error occurs when node[] (or at least its members) turn out to be
> empty,
This is not the problem.
> you get a Traceback that ends with:-
>
> File "/usr/lib/jbrout/jbrout/listview.py", line 608, in draw_cell layout.set_text(self.get_text(thumbnail_num))
> File "/usr/lib/jbrout/jbrout.py", line 325, in get_text ", ".join(node.tags),
> TypeError: sequence item 0: expected string, NoneType found
The specific problem is that node.tags is supposed to be a sequence of
strings and somehow one instead has None as the first, and probably last
item. This was likely intended to indicate an empty list, but the way to
do that is to have a empty list, which would have worked just fine. In
other words, the likely problem is that node.tags is *not* an empty
sequence when it should be.
>>> ','.join([None])
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
','.join([None])
TypeError: sequence item 0: expected str instance, NoneType found
>>> ','.join([])
''
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What's the tidy/elegant way to protect this against null/empty parameters? tinnews@isbd.co.uk - 2012-10-15 12:23 +0100
Re: What's the tidy/elegant way to protect this against null/empty parameters? Paul Rubin <no.email@nospam.invalid> - 2012-10-15 04:49 -0700
Re: What's the tidy/elegant way to protect this against null/empty parameters? Chris Rebert <clp2@rebertia.com> - 2012-10-15 04:58 -0700
Re: What's the tidy/elegant way to protect this against null/empty parameters? Roy Smith <roy@panix.com> - 2012-10-15 08:00 -0400
Re: What's the tidy/elegant way to protect this against null/empty parameters? Miki Tebeka <miki.tebeka@gmail.com> - 2012-10-15 06:33 -0700
Re: What's the tidy/elegant way to protect this against null/empty parameters? Terry Reedy <tjreedy@udel.edu> - 2012-10-15 11:45 -0400
Re: What's the tidy/elegant way to protect this against null/empty parameters? Marco Nawijn <nawijn@gmail.com> - 2012-10-16 03:07 -0700
Re: What's the tidy/elegant way to protect this against null/empty parameters? tinnews@isbd.co.uk - 2012-10-16 14:44 +0100
csiph-web