Hello guys,
OK, I've been reading some more about Python. There are some things
about Python exception that I haven't been able to grasp:
1. This is a small thing, but why is object spelled "object", and the
mother of all exception "Exception" (with capital E)? Why is not object
spelled "Object" then? Especially since Exception's descendants are
named with the first letter of each word capitalized? I mean, in Java,
it's Object. Whereas in C++, they're quite consistent, standard stuff
are usually all lowercaps (basic_string, iostream, etc.). Python seems
to have a mix of both.
Am I right in assuming that object is object (with lower case 'o')
because it is built-in, and Exception is not? So when we write our own
classes, exceptions, etc., we should capitalize it like in Java or C#?
By the way, what's the convention for functions? It's a bit confusing
because when I see Python builtins, it seems that they follow C++ style
(e.g.: has_key, readline). So... does it mean that when I write my own
function, customarily I'd say myFunction() (or MyFunction()?)
2. I'm quite baffled that you either have try/except, or try/finally.
In Java, it is quite common to do this:
try {
// something
} catch(AException e) {
// handle
} catch(BException e) {
// handle
} catch(CException e) {
// handle
} finally {
// whatever happens, execute this
}
It seems that since except and finally are mutually exclusive I can't
do this. So... what's the usual idiom for this?
Thanks!
Ray 8 1948
Ray wrote: Hello guys,
OK, I've been reading some more about Python. There are some things about Python exception that I haven't been able to grasp:
1. This is a small thing, but why is object spelled "object", and the mother of all exception "Exception" (with capital E)? Why is not object spelled "Object" then?
I would guess that object is considered a primitive/basic type like int
or float or string.
I mean, in Java, it's Object. Whereas in C++, they're quite consistent, standard stuff are usually all lowercaps (basic_string, iostream, etc.). Python seems to have a mix of both.
Yeah java capitalizes anything that is a class like String, Object,
Integer, and lowercases its primitives like int, byte.
By the way, what's the convention for functions? It's a bit confusing because when I see Python builtins, it seems that they follow C++ style (e.g.: has_key, readline). So... does it mean that when I write my own function, customarily I'd say myFunction() (or MyFunction()?)
Yeah, the python standard library has been built by lots of different
people. It wasn't designed by one entity using one standard like the
java standard library or .NET/Mono class library.
2. I'm quite baffled that you either have try/except, or try/finally.
Apparently that will be fixed sometime: http://python.miscellaneousmirror.or.../pep-0341.html
D H wrote: Yeah, the python standard library has been built by lots of different people. It wasn't designed by one entity using one standard like the java standard library or .NET/Mono class library.
Um, OK, so is it customary in modern Python programs to follow Java
convention? then methods/functions should be written someMethod() or
myFunction()? 2. I'm quite baffled that you either have try/except, or try/finally.
Apparently that will be fixed sometime: http://python.miscellaneousmirror.or.../pep-0341.html
Ah, okay. I'm quite surprised to see the date--it was _that_ recent! :)
But currently, how have you--Python guys who code for a living--been
handling this case? I know that you can put another try inside a try,
but obviously the need for that is not common enough in idiomatic
Python program (or else this would have been a PEP in, say, 2000).
Cheers
Ray
For youtr try, except, finally:
you can construct something like this:
try:
try:
print 'egg' + 1
except ValueError, e:
print e
finally:
print 'spam'
It results in:
py>
spam
Traceback (most recent call last):
File "C:/Martin/test.py", line 3, in -toplevel-
print 'egg' + 1
TypeError: cannot concatenate 'str' and 'int' objects
py>
If you catch the TypeError you get:
try:
try:
print 'egg' + 1
except TypeError, e:
print e
finally:
print 'spam'
py>
cannot concatenate 'str' and 'int' objects
spam
py>
In article <11**********************@o13g2000cwo.googlegroups .com>,
Ray <ra********@yahoo.com> wrote: 2. I'm quite baffled that you either have try/except, or try/finally. In Java, it is quite common to do this:
try { // something } catch(AException e) { // handle } catch(BException e) { // handle } catch(CException e) { // handle } finally { // whatever happens, execute this }
It seems that since except and finally are mutually exclusive I can't do this. So... what's the usual idiom for this?
Keep in mind that Python actually predates Java. The way this is
handled now is
try:
try:
except:
else:
finally:
Way back when, Guido thought that it would be confusing to allow both
except and finally clauses in the same try because people wouldn't know
what ordering to use (particularly with the else clause).
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/
The way to build large Python applications is to componentize and
loosely-couple the hell out of everything.
Ray wrote: Hello guys,
OK, I've been reading some more about Python. There are some things about Python exception that I haven't been able to grasp:
1. This is a small thing, but why is object spelled "object", and the mother of all exception "Exception" (with capital E)? Why is not object spelled "Object" then?
I always wondered too... But then, you'll notice that Python's builtin
types are usually all lowercase.
(snip)
So when we write our own classes, exceptions, etc., we should capitalize it like in Java or C#?
Yes, definitively.
By the way, what's the convention for functions? It's a bit confusing because when I see Python builtins, it seems that they follow C++ style (e.g.: has_key, readline). So... does it mean that when I write my own function, customarily I'd say myFunction() (or MyFunction()?)
The all_lower_underscore is the common usage, at least in the std lib,
but feel free to use your favorite convention for this. It's up to you
as long as you stick to a given convention for a whole project.
2. I'm quite baffled that you either have try/except, or try/finally.
yes, it's a PITA.
In Java, it is quite common to do this:
(snip) It seems that since except and finally are mutually exclusive I can't do this. So... what's the usual idiom for this?
try:
try:
do_something()
except Exception, e:
handle_error(e)
else:
do_this_too()
finally:
do_this_whatever()
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
"Ray" <ra********@yahoo.com> writes: D H wrote: Yeah, the python standard library has been built by lots of different people. It wasn't designed by one entity using one standard like the java standard library or .NET/Mono class library.
Um, OK, so is it customary in modern Python programs to follow Java convention? then methods/functions should be written someMethod() or myFunction()?
> 2. I'm quite baffled that you either have try/except, or try/finally.
Apparently that will be fixed sometime: http://python.miscellaneousmirror.or.../pep-0341.html
Ah, okay. I'm quite surprised to see the date--it was _that_ recent! :) But currently, how have you--Python guys who code for a living--been handling this case? I know that you can put another try inside a try,
It's what I do, and I'm not bothered by it, TBH. Nested try's have an
explicitness bonus.
Cheers,
mwh
--
Anything that doesn't autonomously leave the fridge, or at the very
least waves protest banners, will be eaten. -- Rik Steenwinkel, asr This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: PT |
last post by:
Hi,
I'm not looking to get into a debate about case-sensitive vs.
insensitive programming languages,
but I was looking for suggestions about how it might be possible to
add a hook to the python...
|
by: John J. Lee |
last post by:
Anybody know when 2.4b1 is currently planned for release?
I'm sure I saw somebody in python-dev mention a date, but I can't find
that post now.
John
|
by: Terry Reedy |
last post by:
According to PCGamer, Jan05, p52:
"*Civilization IV* has been
designed to fully support the mod community. The game is written using
flexible XML data files and the Python scripting language...
|
by: Xah Lee |
last post by:
python has this nice unicodedata module that deals with unicode nicely.
#-*- coding: utf-8 -*-
# python
from unicodedata import *
# each unicode char has a unique name.
# one can use the...
|
by: Corepaul |
last post by:
I am new to Access 2000. My operating system is Windows 2000.
In the early stage of development I noticed something weird. On my form, I have
a Command Button named "btnAlbumUp". The first time...
|
by: liorm |
last post by:
Hi everyone,
I need to write a web app, that will support millions of user accounts,
template-based user pages and files upload. The client is going to be
written in Flash. I wondered if I coudl...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| | |