Package Bio :: Package Phylo :: Module _sugar
[hide private]
[frames] | no frames]

Source Code for Module Bio.Phylo._sugar

 1  # Copyright (C) 2010 by Eric Talevich (eric.talevich@gmail.com) 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license. Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  """Short helper functions (syntax sugar) used in Bio.Phylo. 
 7   
 8  The amount of code in this file should be kept to a minimum. 
 9  """ 
10  __docformat__ = "epytext en" 
11   
12   
13 -def iterlen(items):
14 """Count the number of items in an iterable. 15 16 Exhausts a generator, but doesn't require creating a full list. 17 """ 18 for i, x in enumerate(items): 19 count = i 20 return count + 1
21 22
23 -def trim_str(text, maxlen=60):
24 """Truncate a string to maxlen characters, including ellipsis.""" 25 assert isinstance(text, basestring), \ 26 "%s should be a string, not a %s" % (text, type(text)) 27 if len(text) > maxlen: 28 return text[:maxlen-3] + '...' 29 return text
30