That's not doing what you think: it's getting the first element each time. It only appears to work because all the levels are called "ref". If you called them 'foo.bar.baz' it would fail. You need to actually use the element from the last iteration each time:
def get_ref(ref_attr):
item = f
for attr in ref_attr.split('.'):
item = getattr(item, attr)
print item
But no, there's no built-in way of doing this.