472,354 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

Re: NoneType Error

En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma*******@gmail.comescribió:
I am using a python program on a lot of different documents and for few of
them I will get NoneType error. I just want to skip those files and continue
for others, I do this without a problem for
IndexError,TypeError,ValueError,NameError :

try:
....
except (IndexError,TypeError,ValueError,NameError):
....

but when I add NoneType it gives the following error:
except (NoneType,IndexError,TypeError,ValueError,NameErro r):
NameError: name 'NoneType' is not defined

and if I do not use the NoneType then it does not go through either and
stops the program when I get to such a file. Is there another name that
captures this error?
NoneType is not an exception, but the type of the None object. Perhaps you're not interpreting correctly some error messages:
>>x=None
x()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable

(the exception raised is a TypeError; NoneType is part of the message).

It appears that you want to catch all exceptions, just use Exception for that:
try:
...
except Exception:
...

--
Gabriel Genellina

Jun 27 '08 #1
2 7310
Gabriel Genellina a écrit :
En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma*******@gmail.comescribió:
(snip)
It appears that you want to catch all exceptions, just use Exception for that:
try:
...
except Exception:
...
Hem... That's definitively *not* an a good advice here IMHO. A catch-all
may be useful near a program's 'top-level' to handle any other unhandled
exception in a more user-friendly way (ie : log the error, warns whoever
is in charge, try to cleanly dispose of resources / data / whatever so
we don't break anything, and display a nice and visible error message to
the user), but anywhere else you really want to know *exactly* which
exception(s) you're expecting to handle here and let the other propagate.
Jun 27 '08 #2
En Mon, 16 Jun 2008 06:29:09 -0300, Bruno Desthuilliers <br********************@websiteburo.invalidescribi ó:
Gabriel Genellina a écrit :
>It appears that you want to catch all exceptions, just use Exception for that:
try:
...
except Exception:
...

Hem... That's definitively *not* an a good advice here IMHO. A catch-all
may be useful near a program's 'top-level' to handle any other unhandled
exception in a more user-friendly way (ie : log the error, warns whoever
is in charge, try to cleanly dispose of resources / data / whatever so
we don't break anything, and display a nice and visible error message to
the user), but anywhere else you really want to know *exactly* which
exception(s) you're expecting to handle here and let the other propagate.
Yes, thanks for putting it perfectly clear - more clear than I could have written.

--
Gabriel Genellina

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Atul Kshirsagar | last post by:
Hello, I am using Python 2.3.2 with a C++ extention DLL in muti-threaded environment. 1. For each new thread I create a separate sub-interpreter. 2. Each thread executes multiple python...
3
by: Martin Koekenberg | last post by:
Hello, Ik get the following error when I install a new Python software package such as Zope or PIL. This is what I get whem I 'make' Zope : running build_ext Traceback (most recent call...
1
by: homepricemaps | last post by:
if i do the following i get the url of an image i am looking for image = "" image = bs.img print image however if i do this out.write (image ) i get an error that says "nonetype error is...
5
by: Jon Bowlas | last post by:
Hi listers, I wrote this script in Zope some time ago and it worked for a while, but now I'm getting the following error: TypeError: coercing to Unicode: need string or buffer, NoneType found ...
0
by: John Allman | last post by:
Hi all, I'm trying to create a setup which allows a program to request an object using strings and get an object of that type. It appears to be mostly working but i have difficulties if i...
9
by: thompson.marisa | last post by:
Hi. I'm extremely new to Python and programming as a whole. I have written a python script with the assistance of ESRI ArcGIS 9.2, which uses Python 2.4.1, however, it gives me this error when...
5
by: tom | last post by:
Hi! My code is And it gives following error: How can sortedList variable turn into NoneType? I just don't get it...
2
by: Jordan Harry | last post by:
I'm trying to write a simple program to calculate permutations. I created a file called "mod.py" and put the following in it: def factorial(n): a = n b = n while a>0 and b>1: n = (n)*(b-1)...
0
by: =?utf-8?q?C=C3=A9dric_Lucantis?= | last post by:
Hi, Le Sunday 15 June 2008 10:35:18 Maryam Saeedi, vous avez écrit : you can get the none type with None.__class__ or with the 'types' module, but it won't work as the except handler only...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.