我想编写一个函数,其参数可以是:
例如symlink(target_or_targets, destination)
,可以称为:
symlink(target, destination)
symlink([target1, target2], destination)
如何测试单个参数,并将其转换为包含一项的列表?
答案 0 :(得分:0)
更严格的版本:
if type(target_or_targets) not in (list, set, tuple):
targets = [target_or_targets]
更宽松:
if not isinstance(target_or_targets, (list, set, tuple)):
targets = [target_or_targets]