473,880 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: NoneType Error

En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma*******@gmai l.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,Type Error,ValueErro r,NameError :

try:
....
except (IndexError,Typ eError,ValueErr or,NameError):
....

but when I add NoneType it gives the following error:
except (NoneType,Index Error,TypeError ,ValueError,Nam eError):
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 7468
Gabriel Genellina a écrit :
En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma*******@gmai l.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************ ********@websit eburo.invalides cribió:
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
13121
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 statements calling the class objects in my extention DLL. 3. Before each execution I import my extention module using;
3
11580
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 last): File "/usr/local/zope/Zope-2.7.2-0/setup.py", line 1091, in ?
1
11178
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 not callable"
5
20028
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 Here's my script: results = context.module_retriever().tuples() # call to ZSQLMethod converted =
0
1895
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 attempt to load a module at runtime and then request an object of that type. Essentially, my code works as follows: I have a registry class which has a method to register a class. It
9
24071
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 I try to run it. I've already posted at ESRI support, and I was hoping that Python people could help me more. I hope there is something simple I could do to be able to define the object that it thinks is NoneType. Please when someone responds,
5
15610
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
8493
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) b = b-1 def perm(n, r):
0
240
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 accepts Exception classes. It sounds like you're confusing with some other error, what is the exact message of your 'NoneType error' ? The exception type you want to catch should be at the beginning of it (as in 'TypeError: blah blah...')
0
9772
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11089
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10713
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10809
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9550
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7948
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5777
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4595
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4192
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.