Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31314

Re: What's the tidy/elegant way to protect this against null/empty parameters?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeeder.ewetel.de!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '*not*': 0.07; 'item.': 0.07; 'override': 0.07; 'empty,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'typeerror:': 0.09; 'def': 0.10; 'producing': 0.15; "']'": 0.16; 'fine.': 0.16; 'members)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject: \n ': 0.16; 'subject:parameters': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'instance,': 0.17; 'string,': 0.17; 'jan': 0.18; '>>>': 0.18; '(or': 0.18; 'skip:" 30': 0.20; 'supposed': 0.21; '"",': 0.22; 'occurs': 0.22; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'skip:" 20': 0.26; '(most': 0.27; 'am,': 0.27; 'first,': 0.27; 'header:X-Complaints-To:1': 0.28; 'subject:/': 0.28; 'installed,': 0.29; 'node': 0.29; 'str': 0.29; 'probably': 0.29; "skip:' 10": 0.30; 'worked': 0.30; 'ends': 0.30; 'function': 0.30; 'error': 0.30; 'code': 0.31; 'problem.': 0.32; 'file': 0.32; 'skip:s 30': 0.33; 'skip:l 40': 0.33; 'traceback': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'sequence': 0.35; 'expected': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 0.36; 'be.': 0.36; 'should': 0.36; 'turn': 0.36; 'item': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'list,': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'skip:n 10': 0.63; 'subject:this': 0.84; 'received:fios.verizon.net': 0.84; 'subject:against': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: What's the tidy/elegant way to protect this against null/empty parameters?
Date Mon, 15 Oct 2012 11:45:43 -0400
References <1b8tk9-un9.ln1@chris.zbmc.eu>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0
In-Reply-To <1b8tk9-un9.ln1@chris.zbmc.eu>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2216.1350315959.27098.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350315959 news.xs4all.nl 6988 [2001:888:2000:d::a6]:44485
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31314

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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