Tim Chase wrote:
Carl Banks wrote:
What if the object is a string you just read from a file?
How do you dispatch using polymorphism in that case?
[snip]
which would nicely change into something like
switch row['recordtype']:
case '01':
phone.international += Decimal(row['internationalcost'])
// optionally a "break" here depending on
// C/C++/Java/PHP syntax vs. Pascal syntax which
// doesn't have fall-through
case '02':
phone.text_messaging += (
int(row['textmessages sent']) +
int(row['pages received']) +
int(row['textmessages sent']) +
int(row['pages received'])
...
default:
raise WhatTheHeckIsThis()
This doesn't convert well (i.e. compactly) to a dictionary-dispatch
idiom. :(
Shouldn't 'case' be indented to the same level as 'switch'? And
'default' could be replaced by 'else' without ambiguity.
--
http://mail.python.org/mailman/listinfo/python-list