473,770 Members | 6,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error when using Custom Exception defined in a different python module.

Hi,

I am hitting this error consistently and don't know why it's
happening. I would like to define all exceptions for my project in one
file and use them across the project. Here's a sample -

exceptions.py -

class MyException(Sta ndardError):
def __init__(self, error):
self.myerror = error

tests.py -

from exceptions import *

class Test:
def __init__(self,f ilename):
if filename == "":
raise MyException("Ra ise custom error")

if __name__ == "__main__" :
test = Test("")
When the above is run, I get the following error -
NameError: global name 'MyException' is not defined

Thanks
loganwol

May 6 '07 #1
2 5295
wrote in news:11******** **************@ e65g2000hsc.goo glegroups.com in
comp.lang.pytho n:
Hi,

I am hitting this error consistently and don't know why it's
happening. I would like to define all exceptions for my project in one
file and use them across the project. Here's a sample -

exceptions.py -
from exceptions import *
raise MyException("Ra ise custom error")

When the above is run, I get the following error -
NameError: global name 'MyException' is not defined

When you get this kind of error, goto a python prompt
(type python at a command prompt, or click on IDLE)
and try this:
>>import exceptions
help( exceptions )
I got this response (clipped):

Help on built-in module exceptions:

NAME
exceptions - Python's standard exception class hierarchy.

Another common module name to avoid is "test".

Rob.
--
http://www.victim-prime.dsl.pipex.com/
May 6 '07 #2
On May 6, 11:23 am, Rob Williscroft <r...@freenet.c o.ukwrote:
wrote innews:11****** *************** *@e65g2000hsc.g ooglegroups.com in
comp.lang.pytho n:
Hi,
I am hitting this error consistently and don't know why it's
happening. I would like to define all exceptions for my project in one
file and use them across the project. Here's a sample -
exceptions.py -
from exceptions import *
raise MyException("Ra ise custom error")
When the above is run, I get the following error -
NameError: global name 'MyException' is not defined

When you get this kind of error, goto a python prompt
(type python at a command prompt, or click on IDLE)
and try this:
>import exceptions
help( exceptions )

I got this response (clipped):

Help on built-in module exceptions:

NAME
exceptions - Python's standard exception class hierarchy.

Another common module name to avoid is "test".

Rob.
--http://www.victim-prime.dsl.pipex .com/
Doh!

Thanks for correcting my error Rob.

May 6 '07 #3

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

Similar topics

7
4615
by: Xah Lee | last post by:
Python doc problem: http://python.org/doc/2.4.2/lib/os-file-dir.html makedirs( path) Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory. Throws an error exception if the leaf directory already exists or cannot be created. The default mode is 0777 (octal). This function does not properly handle UNC paths (only relevant on Windows systems;
6
4753
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
6
1588
by: Steve Amey | last post by:
Hi all I want to be able to throw a custom error up the call stack. I have looked around and it seems as though it's possible, but I can't get it to work :o( Below is some sample code. ------------------------------------------------------------ Public Class MainForm Public Sub Show Form Try
6
4446
by: aomighty | last post by:
I wanted to write the following code: import shelve try: db = shelve.open(file, "r") except SomeError: print "Oh no, db not found" Only, I'm not sure what SomeError should be. I tried error, anydbm.error, shelve.open.anydb.error, etc. but can't find it. Things
5
3508
by: Jeff | last post by:
Okay, I'm still new to vb.net 2005 - throught this was a hardware problem, but now I don't know. (I'm having some problem with my newgroup provider, so hopefully this will go through) This problem just started about a week ago, before all was fine. I'm using the code below to access a mysql database. On the line indicated when the connection is opened, the application has been sporatically drawing an error. It doesn't occur very often -...
2
7460
by: Gabriel Genellina | last post by:
En Sun, 15 Jun 2008 05:35:18 -0300, Maryam Saeedi <ma.saeedi@gmail.comescribió: NoneType is not an exception, but the type of the None object. Perhaps you're not interpreting correctly some error messages: 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).
4
2515
by: Cirene | last post by:
In my web.config I added <pages enableSessionState="true">. In each of my pages I also added EnableSessionState="True" to the Page declaration. (I didn't think this was necessary, but...) Any reason why even though I did this I keep getting this error.... Server Error in '/abc' Application.
2
19491
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
10231
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
9871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8887
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
7416
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
6679
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
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
3972
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
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.