[Pyrex] TypeError: exceptions must be strings, classes, or instances, not type

Lenard Lindstrom len-l at telus.net
Wed Apr 23 06:36:02 CEST 2008


Quoting Yang Zhang <yanghatespam at gmail.com>:

> Yang Zhang wrote:
> > Hi, I'm trying to use this Pyrex module:
> > 
> > http://code.google.com/p/pypcap/
> > 
> > but I get:
> > 
> > Traceback (most recent call last):
> >   File "./analyze.py", line 11, in <module>
> >     for x in pc: xs.append(x)
> >   File "pcap.pyx", line 346, in pcap.pcap.__next__
> > TypeError: exceptions must be strings, classes, or instances, not type
> > 
> > because the places marked "here" below are apparently doing something 
> > that Pyrex can't handle:
> > 
> >     def __next__(self):
[snip code]
> >             elif n == -1:
> >                 raise KeyboardInterrupt # here
> >             elif n == -2:
> >                 raise StopIteration # here
> > 
> > Does anybody know what's going on? Are exceptions not allowed in Pyrex? 
> > Is there a workaround?
> > 
> > Thanks in advance for any answers!
> 
> Just to clarify: I also retried with the latest pyrex (0.9.6.4), with 
> the same results.  Also I'm using Python 2.5 on Ubuntu 7.10 (I tried 
> with the distro-supplied pyrex initially).
> 
Exceptions can be raised in Pyrex just as in Python, with an instance of an 
exception type:

                 raise KeyboardInterrupt("optional message goes here")


-- 
Lenard Lindstrom
<len_l at telus.net>




More information about the Pyrex mailing list