At the suggestion of one of my correspondents, I slightly reluctantly
implemented an RSS feed for my website/writing. It is perhaps a bit
crude so far, but maybe I'll spiff it up. The RSS also has an HTML
front to it.
If you want to see the latest news about my _Charming Python_ or _XML
Matters_ columns, or about other articles (later, perhaps stuff about
my book), take a look at: http://gnosis.cx/rss.xml
Or http://www.gnosis.cx/publish/whatsnew.html
I'm new to this RSS stuff... so let me know (gently) if I've done
anything terribly wrong.
--
mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o
gnosis _/_/ Postmodern Enterprises \_\_
..cx _/_/ \_\_ d o
_/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e 3 2383
"Raymond Hettinger" <vz******@veriz on.net> writes:
[...] ACT I --------------------------------------- s = list('abc') try: ... result = s['a'] ... except IndexError, TypeError: ... print 'Not found' ...
Traceback (most recent call last): File "<pyshell#1 1>", line 2, in -toplevel- result = s['a'] TypeError: list indices must be integers
The second 'argument' of except is the caught exception object, so
that code works as if you did
try:
result = s['a']
except IndexError, e:
TypeError = e
print 'Not found'
-- which doesn't catch the TypeError.
ACT II -------------------------------------------- class MyMistake(Excep tion): ... pass try: ... raise MyMistake, 'try, try again' ... except MyMistake, msg: ... print type(msg) ...
<type 'instance'>
Again, the second 'argument' of except gets the exception object, not
the string you used in the raise.
These two are equivalent [XXX er, I *think* they're always equivalent]:
raise SomeError, 'my error message'
raise SomeError('my error message')
The second form is more explicit, hence better.
Exception objects do have a __str__ method, though, so you can print
them as if they were strings:
try:
result = s['a']
except IndexError, e:
print e
because print calls the e.__str__ method to do its work.
ACT III -------------------------------------------- class Prohibited(Exce ption): ... def __init__(self): ... print 'This class of should never get initialized' ... raise Prohibited() This class of should never get initialized
Traceback (most recent call last): File "<pyshell#4 0>", line 1, in -toplevel- raise Prohibited() Prohibited: <unprintable instance object> raise Prohibited This class of should never get initialized
Traceback (most recent call last): File "<pyshell#4 1>", line 1, in -toplevel- raise Prohibited Prohibited: <unprintable instance object>
These are equivalent:
raise Exception
raise Exception()
The second is more explicit, hence better.
Since exception classes always end up getting instantiated whichever
way you write the raise statement, you need to write __init__
correctly if you override it. The Exception base class has an
__init__ that it expects to be called, so you should call it:
[At this point, I had to look up the arguments to Exception.__ini t__.]
class Prohibited(Exce ption):
def __init__(self, *args):
Exception.__ini t__(self, *args)
print 'This class will get initialized'
In this case, the lack of that Exception.__ini t__ call is what's
causing the "<unprintab le instance object>" message, but it could
cause other problems too.
[Actually, with your interactive example, I don't get the
"<unprintable.. ." bit -- maybe that's in 2.3b2...]
ACT IV ----------------------------------------------- module = 'Root' try: ... raise module + 'Error' ... except 'LeafError': ... print 'Need leaves' ... except 'RootError': ... print 'Need soil' ... except: ... print 'Not sure what is needed' ...
Not sure what is needed
A raised string exception only matches the string in the except
statment if both strings are the same object. It's not enough for
them to have the same value. Two different string literals that have
the same value aren't necessarily the same object:
myerror = "myerror"
anothererror = "myerror" # not *necessarily* the same object as myerror
try:
raise myerror
except anothererror:
# we only get here if it so happens that:
assert myerror is anothererror
except myerror:
# we always get here, because:
assert myerror is myerror
ACT V ----------------------------------------------- try:
... raise KeyError('Canno t find key') ... except LookupError, msg: ... print 'Lookup:', msg ... except OverflowError, msg: ... print 'Overflow:', msg ... except KeyError, msg: ... print 'Key:', msg
Lookup: 'Cannot find key'
except statements are checked in the order you write them. Class
instance exceptions are matched as if by
isinstance(rais ed_exception, caught_exceptio n)
so exceptions can be caught by their base classes. LookupError is a
base class of KeyError, so the first except matches.
John
John J. Lee wrote: "Raymond Hettinger" <vz******@veriz on.net> writes: [...]
ACT I ---------------------------------------
(snip)
John,
is it my newsreader going mad, or did you post in the wrong thread ?
Bruno
Bruno Desthuilliers <bd***********@ removeme.free.f r> writes: John J. Lee wrote: "Raymond Hettinger" <vz******@veriz on.net> writes: [...]
ACT I ---------------------------------------
(snip)
John, is it my newsreader going mad, or did you post in the wrong thread ?
I posted in the wrong thread.
Something about Gnus... haven't figured out why I occasionally do that yet.
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: thecrow |
last post by:
Alright, what the hell is going on here?
In the following code, I expect the printed result to be:
DEBUG: frank's last name is burns.
Instead, what I get is:
DEBUG: frank's last name is burns.
Here is the code:
$frank = "burns";
|
by: Brandon J. Van Every |
last post by:
What's better about Ruby than Python? I'm sure there's something. What is
it?
This is not a troll. I'm language shopping and I want people's answers. I
don't know beans about Ruby or have any preconceived ideas about it. I have
noticed, however, that every programmer I talk to who's aware of Python is
also talking about Ruby. So it seems that Ruby has the potential to compete
with and displace Python. I'm curious on what basis it...
|
by: Mike Henley |
last post by:
I first came across rebol a while ago; it seemed interesting but then
i was put off by its proprietary nature, although the core of the
language is a free download.
Recently however, i can't help but say i was totally impressed. I
needed an open source wikiblog/wikilog, whatever you wanna call it,
basically a hybrid of a blog and a wiki. I checked out snipsnap, which
uses java, it was said on their site to be a clone of vanilla, a...
|
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro capabilities, unfortunately. I'd like to know if it may
be possible to add a powerful macro system to Python, while
keeping its amazing syntax, and if it could be possible to
add Pythonistic syntax to Lisp or Scheme, while keeping all
of the...
|
by: David Mertz, Ph.D. |
last post by:
Python/XML users might be interested in:
http://www-106.ibm.com/developerworks/xml/library/x-matters39.html
Title:
Get the most out of gnosis.xml.objectify
Subtitle:
Use utility functions for enhanced object behavior
| |
by: Reed L. O'Brien |
last post by:
I see rotor was removed for 2.4 and the docs say use an AES module
provided separately... Is there a standard module that works alike or
an AES module that works alike but with better encryption?
cheers,
reed
|
by: hacker1017 |
last post by:
im just asking out of curiosity.
|
by: Katie Tam |
last post by:
I am new to this filed and begin to learn this langague. Can you tell
me the good books to start with ?
Katie Tam
Network administrator
http://www.linkwaves.com/main.asp
http://www.linkwaves.com
|
by: Wang, Harry |
last post by:
The gnosis xml libs should not be version specific, but when I try to use Python 2.5, I am getting "not well formed (invalid token)" errors.
Harry
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |