def strip_comment(string, comment_characters=('!',), quote_characters=('"',
    "'")):
    """
    Return the string only until the first comment (if any), but makes
    sure to ignore comments if inside a string

    Note: it expects to get a SINGLE line, without newline characters

    Note: it does not cope with escaping of quotes

    :param string: the string to check
    :param comment_characters: a list or tuple of accepted comment characters
    :param quote_characters: a list or tuple of accepted valid string characters
    """
    new_string = []
    in_string = False
    string_quote = None
    for char in string:
        if char == '\n':
            raise ValueError(
                'I still cannot cope with newlines in the string...')
        if in_string and char == string_quote:
            in_string = False
            string_quote = None
        elif not in_string and char in quote_characters:
            in_string = True
            string_quote = char
        if not in_string and char in comment_characters:
            return ''.join(new_string)
        new_string.append(char)
    if in_string:
        raise ValueError(
            'String >>{}<< is not closed, it was open with the {} char'.
            format(string, string_quote))
    return string
