import re def _formatPrice(price, symbol='€'): '''_formatPrice(price, symbol='€'): Gets a floating point value and returns a formatted price, suffixed by 'symbol'. ''' s = ("%.2f" % price).replace('.', ',') pat = re.compile(r'([0-9])([0-9]{3}[.,])') while pat.search(s): s = pat.sub(r'\1.\2', s) return s + ' ' + symbol def split_to_width(s, length): '''Fügt zeilenumbrüche in einen String ein, dass er maximal 'length' Zeichen lang ist''' orig = s ret = [] while len(s) > 0: if len(s) < length: ret.append(s) s = '' else: index = s.rfind(' ', 0, length) if index == -1: index = length ret.append(s[:index]) s = s[index + 1:] return ret