def varchar(n):
    """varchar(n) converts an object into a string with less than n
    characters or raises a TypeError"""
    def check(x):
        s = str(x)
        if len(s) > n:
              raise TypeError('Entered a string longer than %d chars' % n)
        return s
    check.__name__ = 'varchar(%d)' % n
    return check