I have a function where I need to generate different output strings for another program I invoke, depending on which type it wants.
Basically, the called program needs a command line argument telling it which type it was called with.
Happily I found this answer on SO on how to check a variable for type. But I noticed how people also raised objections, that checking for types betrays a "not object oriented" design. So, is there some other way, presumable more "more object oriented" way of handling this without explicitly checking for type?
The code I have now goes something like this:
def myfunc(val):
cmd_type = 'i'
if instance(val, str):
cmd_type = 's'
cmdline = 'magicprogram ' + cmd_type + ' ' + val
Popen(cmdline, ... blah blah)
...
which works just fine, but I just wanted to know if there is some technique I am unaware of.