On Sat, Oct 24, 2009 at 10:00 AM, Mark (Nosrednakram) < nosrednak...@gmail.com> wrote:
> def using_reversion(): > try: > import reversion > return True > except ImportError: > return False > except: > pass > I'd still leave out the `bare except` entirely so other potential errors from `import reversion` don't get mysteriously swallowed. http://www.python.org/dev/peps/pep-0008/ (Python Style Guide) talks about catching specific exceptions, under "Programming Recommendations." > def using_cache(): > if len(getattr(settings,'CACHE_BACKEND',0)) > 0: > return True > else: > return False > Careful -- in `getattr(settings, 'CACHE_BACKEND', 0)` the result will be 0 if there's no settings.CACHE_BACKEND. I just tried passing this to len() because I wasn't sure whether it would work; it doesn't: Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> len(0) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: object of type 'int' has no len() So you should use the (zero-length) empty string as the default instead of 0. Regards, egj --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---