But I noticed how people also raised objections, that checking for types betrays a "not object oriented" design
This is actually called the duck print style ("If it looks like a duck and quacks, like a duck, it must be a duck"). And it is a python language that recommends using this programming style.
and with a duck set, call EAFP (it's easier to ask forgiveness than permission)
presumable more "more object oriented" way of handling this without explicitly checking for type?
you mean more pythonic, basically what will be more pythonic in your case looks something like this:
def myfunc(val): cmd_type = 'i'
and in your magic program (I don’t know if this is your script or ...), and therefore in all cases your program will receive a string, so just try to convert it to script accept;
from optparse import OptionParser
I don’t know what all your code is, but you can follow the example above, it is more pythonic, and remember that each rule has its own exception, so maybe your case is an exception and you better check the type.
Hope this helps you figure it out.
mouad
source share