Elegant imports in place!

This commit is contained in:
Kenneth Reitz
2010-09-25 15:23:01 -04:00
parent dfa26a7d53
commit 4117503ed5
+12 -4
View File
@@ -76,8 +76,12 @@ class Dataset(object):
"""Adds format properties."""
for fmt in formats:
try:
setattr(cls, fmt.title, property(fmt.export_set))
except Exception:
try:
setattr(cls, fmt.title, property(fmt.export_set, fmt.import_set))
except AttributeError:
setattr(cls, fmt.title, property(fmt.export_set))
except AttributeError:
pass
@@ -234,8 +238,12 @@ class Databook(object):
"""Adds format properties."""
for fmt in formats:
try:
setattr(cls, fmt.title, property(fmt.export_book))
except Exception:
try:
setattr(cls, fmt.title, property(fmt.export_book, fmt.import_book))
except AttributeError:
setattr(cls, fmt.title, property(fmt.export_book))
except AttributeError:
pass