Design question regarding exceptions.

2007-07-17 Thread asincero
I have a class called Users that provides a higher level of abstraction to an underlying users table in a pgsql database. It has methods like addUser() and deleteUser() which, obviously, wrap the corresponding SQL statements. My question is would it better to let any exceptions thrown by the

Using a switch-like if/else construct versus a dictionary?

2007-06-19 Thread asincero
Which is better: using an if/else construct to simulate a C switch or use a dictionary? Example: def foo(): if c == 1: doCase1() elif c == 2: doCase2() elif c == 3: doCase3() elif c == 4: doCase4() elif c == 5: doCase5() else: raise shouldn't

Re: Using a switch-like if/else construct versus a dictionary?

2007-06-20 Thread asincero
Ahh .. yes of course, you are right. I mis-typed. I like how you defined the dictionary all in one statement, though. I didn't think of doing it that way. -- Arcadio On Jun 19, 4:11 pm, heltena [EMAIL PROTECTED] wrote: asincero ha escrit: def foo(): def doCase1(): pass

How to catch these kind of bugs in Python?

2006-08-19 Thread asincero
Is there anyway to catch the following type of bug in Python code: message = 'This is a message' # some code # some more code if some_obscure_condition: nessage = 'Some obscure condition occured.' # yet more code # still more code print message In the above example, message should be set to

Is this a good idea or a waste of time?

2006-08-24 Thread asincero
Would it be considered good form to begin every method or function with a bunch of asserts checking to see if the parameters are of the correct type (in addition to seeing if they meet other kinds of precondition constraints)? Like: def foo(a, b, c, d): assert type(a) == str