[Tutor] Trying a csv error
Tim Johnson
tim at johnsons-web.com
Sat Feb 11 00:25:59 CET 2006
Hi Danny:
Thanks!
tim
(who_should_have_read_the_docs)
* Danny Yoo <dyoo at hkn.eecs.berkeley.edu> [060210 13:56]:
> > I'd like to do the following
> > while(1):
> > try:
> > reader.next() ## csv object method
> > except cvs._csv.Error: ## or something like this
> > print "bad csv record, skipping ...."
> > continue
> > except StopIteration:
> > break
> >
> > The problem is that python does not recognize the
> > error objects and gives me:
> > "'module' object has no attribute '_csv'".
> >
> > Any ideas on how to trap this error?
>
> Hi Tim,
>
> According to the bottom of:
>
> http://www.python.org/doc/lib/csv-contents.html
>
> you should be able to check for csv.Error.
>
> """The csv module defines the following exception:
>
> exception Error
> Raised by any of the functions when an error is detected."""
>
>
> Here's what it looks like:
>
> ######
> >>> import csv
> >>> csv.Error
> <class _csv.Error at 0x81b4f8c>
> ######
>
> So internally, csv.Error is the thing you've been seeing, but from the
> API, you should try to ignore that particular internal implementation
> detail, and just use csv.Error instead.
>
>
> Best of wishes!
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Tim Johnson <tim at johnsons-web.com>
http://www.alaska-internet-solutions.com
More information about the Tutor
mailing list