Python Deprecation Error
Contents |
a try statement with an except clause that mentions a particular class, that clause also handles any exception python filenotfounderror classes derived from that class (but not exception classes from which it python custom exception is derived). Two exception classes that are not related via subclassing are never equivalent, even if they
Python Valueerror Example
have the same name. The built-in exceptions listed below can be generated by the interpreter or built-in functions. Except where mentioned, they have an "associated value" indicating the
Python Exception Message
detailed cause of the error. This may be a string or a tuple of several items of information (e.g., an error code and a string explaining the code). The associated value is usually passed as arguments to the exception class's constructor. User code can raise built-in exceptions. This can be used to test an exception handler or to python exception class methods report an error condition "just like" the situation in which the interpreter raises the same exception; but beware that there is nothing to prevent user code from raising an inappropriate error. The built-in exception classes can be subclassed to define new exceptions; programmers are encouraged to derive new exceptions from the Exception class or one of its subclasses, and not from BaseException. More information on defining exceptions is available in the Python Tutorial under User-defined Exceptions. When raising (or re-raising) an exception in an except or finally clause __context__ is automatically set to the last exception caught; if the new exception is not handled the traceback that is eventually displayed will include the originating exception(s) and the final exception. When raising a new exception (rather than using a bare raise to re-raise the exception currently being handled), the implicit exception context can be supplemented with an explicit cause by using from with raise: raise new_exc from original_exc The expression following from
here for a quick overview of the site Help Center Detailed answers to any questions you might
Python Errno
have Meta Discuss the workings and policies of this site About python attributeerror object has no attribute Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting python 3 exceptions ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 https://docs.python.org/3/library/exceptions.html million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up BaseException.message deprecated in Python 2.6 up vote 121 down vote favorite 14 I get a warning that BaseException.message is deprecated in Python 2.6 when I use the following user-defined exception: class MyException(Exception): def __init__(self, message): self.message = message http://stackoverflow.com/questions/1272138/baseexception-message-deprecated-in-python-2-6 def __str__(self): return repr(self.message) This is the warning: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 self.message = message What's wrong with this? What do I have to change to get rid of the deprecation warning? python exception deprecated share|improve this question edited Nov 7 '13 at 16:33 karthikr 52.5k1184106 asked Aug 13 '09 at 13:59 desolat 1,72762342 6 See PEP 352 for the reasons: python.org/dev/peps/pep-0352/#retracted-ideas –balpha♦ Aug 13 '09 at 14:09 add a comment| 8 Answers 8 active oldest votes up vote 107 down vote accepted Solution - almost no coding needed Just inherit your exception class from Exception and pass the message as the first parameter to the constructor Example: class MyException(Exception): """My documentation""" try: raise MyException('my detailed description') except MyException as my: print my # outputs 'my detailed description' You can use str(my) or (less elegant) my.args[0] to access the custom message. Background In the newer versions of Python (from 2.6) we are supposed to inherit our cus
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company http://stackoverflow.com/questions/9008444/how-to-warn-about-class-name-deprecation Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs http://stackoverflow.com/questions/15144168/error-using-deprecated-class-pysimpleapp-after-removing-epd Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to warn about class (name) deprecation up vote 25 down vote favorite 3 I have renamed a python class being a python exception part of a library. I am willing to leave a possibility to use its previous name for some time but would like to warn user that it's deprecated and will be removed somewhere in the future. I think that to provide backward compatibility it will be enough to use an alias like that: class NewClsName: pass OldClsName = NewClsName I have no idea how to mark the OldClsName as deprecated in an elegant way. Maybe python deprecation error I could make OldClsName a function which emits a warning (to logs) and constructs the NewClsName object from its parameters (using *args and **kvargs) but it doesn't seem elegant enough (or maybe it is?). Unfortunately, I don't know how Python standard library deprecation warnings work but I imagine that there may be some nice magic to deal with deprecation, e.g. allowing treating it as errors or silencing depending on some interpreter's command line option. The question is: How to warn users about using an obsolete class alias (or obsolete class in general). EDIT: The function approach doesn't work for me (I already gave it a try) because the class has some class methods (factory methods) which can't be called when the OldClsName is defined as a function. Following code won't work: class NewClsName(object): @classmethod def CreateVariant1( cls, ... ): pass @classmethod def CreateVariant2( cls, ... ): pass def OldClsName(*args, **kwargs): warnings.warn("The 'OldClsName' class was renamed [...]", DeprecationWarning ) return NewClsName(*args, **kwargs) OldClsName.CreateVariant1( ... ) Because of: AttributeError: 'function' object has no attribute 'CreateVariant1' Is inheritance my only option? To be honest, it doesn't look very clean to me - it affects class hierarchy through introduction of unnecessary derivation. Additionally, OldClsName is not NewClsName what is not an issue in most cases but may be a problem in case of poorly writt
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error, Using deprecated class PySimpleApp after removing EPD up vote 2 down vote favorite I am using spyder on Mac OSX 10.8.2 and I had Enthought which I uninstalled. In my code I used pyplot from matplotlib. However I keep getting the following warning when I run the simple plot program. /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_wx.py:1382: wxPyDeprecationWarning: Using deprecated class PySimpleApp. wxapp = wx.PySimpleApp() I tried pip, manual installing of matplotlib and non of them helped. What should I do about it? These are my code lines related to plotting: markerSize=400; fig = plt.gcf() plt.scatter(X,Y,marker='+',s=markerSize) circle=plt.Circle((X[i]+k*meshStep,Y[i]+j*meshStep),frequency/magnification,color='r'); fig.gca().add_artist(circle) plt.xlim(min(X)-1,max(X)+1) plt.ylim(min(Y)-1,max(Y)+1) Before uninstalling Enthought I didn't have this problem and my figure had zoom and move buttons but right now I only get the graph itself. Thank you. python osx matplotlib wxpython share|improve this question edited Feb 28 '13 at 20:07 asked Feb 28 '13 at 19:38 Cupitor 1,76552548 Apparently problem solved. I just deleted any instance of spyder file on pc! Specially the config files in user directory! –Cupitor Feb 28 '13 at 20:30 add a comment| 1 Answer 1 active oldest votes up vote 7 down vote You should use wx.App(False) instead of wx.PySimpleApp. PySimpleApp has been deprecated in wxPython 2.9. wx.App(False) does basically the same thing. share|improve this answer answered Feb 28 '13 at 19:48 Mike Driscoll 24.9k31857 Well the problem is I am not using wx.App(False) at all! –Cupitor Feb 28 '13 at 19:50 2 Right, it is matplotlib that is still using wx.PySimpleApp. The reason you didn't see it with EPD is because they are still using an earlier wxPython 2.8, where wx.PySimpleApp hasn't been deprecated yet. If you run into this in the future you can work