Tagged Questions
7
votes
2answers
1k views
Is it conventional to raise a NotImplementedError for methods whose implementation is pending, but not planned to be abstract?
I like to raise a NotImplementedError for any method that I want to implement, but where I haven't gotten around to doing it yet. I might already have a partial implementation, but prepend it with ...
3
votes
2answers
122 views
Inform caller or just let them deal with exception?
I'm not sure how to proceed in the following situation.
say we have a function as so:
def runsATask(codes):
myDicts = [helperFunc(code) for code in codes]
for item in myDicts:
# some ...
8
votes
3answers
470 views
When and how should I use exceptions (in Python)?
The Setting
I often have trouble determining when and how to use exceptions. Let's consider a simple example: suppose I am scraping a webpage, say "http://www.abevigoda.com/", to determine if Abe ...
31
votes
3answers
2k views
Python Forgiveness vs. Permission and Duck Typing
In Python, I often hear that it is better to "beg forgiveness" (exception catching) instead of "ask permission" (type/condition checking). In regards to enforcing duck typing in Python, is this
try:
...
38
votes
7answers
24k views
Why use try … finally without a catch clause?
The classical way to program is with try / catch but when is it appropriate to use try without catch? In Python the following appears legal and can make sense:
try:
#do work
finally:
#do ...
21
votes
4answers
7k views
Why do iterators in Python raise an exception?
Here's the syntax for iterators in Java (somewhat similar syntax in C#):
Iterator it = sequence.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
Which makes sense. Here's ...