我怎样才能在不无限重复自己的情况下编写这段代码?
fields = row.split('__')
if len(fields) == 1:
foo = getattr(bundle.obj, fields[0])
elif len(fields) == 2:
foo = getattr(getattr(bundle.obj, fields[0]), fields[1])
elif len(fields) == 3:
foo = getattr(getattr(getattr(bundle.obj,
fields[0]), fields[1]), fields[2])
# etc ..