def get_tuple(string, n, as_int = False):
  """
  Splits a string into n tuples, ignoring the rest if there are more, and replicating
  if there is only one

  @param string   The string
  @param n        The number of elements
  @param as_int   If true, it will cast to int
  """
  t = string.split(",")
  if len(t) == n:
    t = tuple(t)
  elif len(t) > n:
    t = tuple(t[:n - 1])
  elif len(t) == 1:
    t = tuple(t * n)
  else:
    raise IndexError("Invalid number of values")

  if as_int:
    return tuple([int(i) for i in t])
  else:
    return t