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


Groups > comp.lang.python > #26191

Re: Python Error

Date 2012-07-29 15:57 +0200
From Jürgen A. Erhard <jae@jaerhard.com>
Subject Re: Python Error
References <81818a9c-60d3-48da-9345-0c0dfd5b25e7@googlegroups.com> <jv35jq$h3d$1@dough.gmane.org>
Organization Lost Worlds Inc. (I keep dreaming)
Newsgroups comp.lang.python
Message-ID <mailman.2689.1343572776.4697.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Jul 29, 2012 at 01:08:57PM +0200, Peter Otten wrote:
> subhabangalore@gmail.com wrote:
> 
> > Dear Group,
> > 
> > I was trying to convert the list to a set, with the following code:
> > 
> > set1=set(list1)
> > 
> > the code was running fine, but all on a sudden started to give the
> > following error,
> > 
> > set1=set(list1)
> > TypeError: unhashable type: 'list'
> > 
> 
> Add a print statement before the offending line:
> 
> print list1
> set1 = set(list1)
> 
> You will see that list1 contains another list, e. g. this works...
> 

Peter's right, but instead of a print before the line, put a
try/except around it, like

   try:
      set1 = set(list1)
   except TypeError:
      print list1
      raise

This way, only the *actual* error triggers any output.  With a general
print before, you can get a lot of unnecessary output.

Grits, J

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python Error subhabangalore@gmail.com - 2012-07-29 02:27 -0700
  Re: Python Error Peter Otten <__peter__@web.de> - 2012-07-29 13:08 +0200
  Re: Python Error subhabangalore@gmail.com - 2012-07-29 05:30 -0700
    Re: Python Error Thomas Jollans <t@jollybox.de> - 2012-07-29 14:45 +0200
    Re: Python Error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-07-29 14:53 +0100
    Re: Python Error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-29 14:01 +0000
    Re: Python Error Emile van Sebille <emile@fenx.com> - 2012-07-29 07:42 -0700
  Re: Python Error Roy Smith <roy@panix.com> - 2012-07-29 10:23 -0400
    Re: Python Error subhabangalore@gmail.com - 2012-07-29 07:41 -0700
  Re: Python Error Jürgen A. Erhard <jae@jaerhard.com> - 2012-07-29 15:57 +0200
    Re: Python Error Duncan Booth <duncan.booth@invalid.invalid> - 2012-07-30 11:15 +0000
  Re: Python Error subhabangalore@gmail.com - 2012-07-29 07:36 -0700
    Re: Python Error Chris Angelico <rosuav@gmail.com> - 2012-07-30 01:12 +1000

csiph-web