def strip_comments(s):
    """Strips comment lines and docstring from Python source string."""
    o = ''
    in_docstring = False
    for l in s.split('\n'):
        if l.strip().startswith(('#', '"', "'")) or in_docstring:
            in_docstring = l.strip().startswith(('"""', "'''")) + in_docstring == 1
            continue
        o += l + '\n'
    return o