Here I am giving an article that makes user defined exceptions in Python. This is continuation of Quick Tutorial of Exception handling in python
User-defined exceptions
By creating a new exception class in your program, you can specify your own exception. Exceptions are typically from the Exception class is derived directly or indirectly. For example:
>>> class MyError(Exception):
… def __init__(self, value):
… self.value = value
… def __str__(self):
… return repr(self.value)
…
>>> try:
… raise MyError(2*2)
… except MyError, e:
… print ‘My exception occurred, value:’, e.value
…
My exception occurred, value: [...]
This artcie mentions small esample of handling exceptions in python
You can write a program such as sorting and processing exceptions. Please see the following example. In this example, but prompts the user for input until a valid string is entered, the user program (Control-C or using the operating system that supports key or some) programs over the interrupt We may be able to disrupt; user-generated interrupts, KeyboardInterrupt Please note that you will be notified that an exception is thrown.
>>> while [...]
Download this simple wallpaper of python
How to sort a list of strings that represent IP addresses? Using the function to the sort() method of the list object is very inefficient. We will pre-process the sorted and then apply comparision function. In the case of IP addresses, we re-format them so that each of the four octets is aligned inside a three-character field. All strings will be the same length and can be sorted using the fast built-in comparison function. Here is the code for it
for [...]
When I write a decorator with a parameter error I found that not even understand. Not only that writing was bad, but was using the wrong. A designer with a parameter and applies (being a designer deco and the argument 1):
@deco(1)
def function_a_decorar(a, b, c):
pass
I think the root of my confusion was the syntactic sugar (yes, the @). So let’s see how to remove it and use this designer in [...]
This is a simple program to access the remote directories using
python. Before accesssing them you need to have proper
permissions on the directories lik \\server\directory…
The below code is written in windows environment. Of course you
can configure it too in linux.
# define a base path and a program to run
base_path = ‘\\\\mynetwork\\testuser\\images\\’
image_viewer = ‘c:\\windows\system32\\rundll32.exe’
image_viewer += ‘ c:\\WINDOWS\\System32
\\shimgvw.dll,ImageView_Fullscreen ‘
# several inputs for different values of ‘loop_idx’ to set
“user_input” list are omitted here – they
# were used to build a path to image that [...]

