def set_function_names_loweru(paths): for path in paths: string = open(path).read() tuples = [(name, set_loweru(name)) for name in find_function_names(string)] for path2 in paths: #must apply in path apply_to_file(path2, lambda s: replace_words(tuples, s))
def set_function_names_loweru(paths): for path in paths: string = open(path).read() tuples = [(name, set_loweru(name)) for name in find_function_names(string)] for path2 in paths: # must apply in path apply_to_file(path2, lambda s: replace_words(tuples, s))
def aux(s): return "_" + s.group(1).lower() string = string[0].lower() + string[1:] return re.sub("(?!^)_?([A-Z])", aux, string) def replace_words(list_tuple, string): for w1, w2 in list_tuple: string = re.sub("(?<!\w)" + w1 + "(?!\w)", w2, string) return string def set_function_names_loweru(paths): for path in paths: string = open(path).read() tuples = [(name, set_loweru(name)) for name in find_function_names(string)] for path2 in paths: # must apply in path apply_to_file(path2, lambda s: replace_words(tuples, s)) if __name__ == "__main__": paths = sys.argv[2:] if len(sys.argv) <= 2: pass elif sys.argv[1] == "blank": for path in paths: apply_to_file(path, set_blanks_lines) elif sys.argv[1] == "names": set_function_names_loweru(paths)
return "_" + s.group(1).lower() string = string[0].lower() + string[1:] return re.sub("(?!^)_?([A-Z])", aux, string) def replace_words(list_tuple, string): for w1, w2 in list_tuple: string = re.sub("(?<!\w)" + w1 + "(?!\w)", w2, string) return string def set_function_names_loweru(paths): for path in paths: string = open(path).read() tuples = [(name, set_loweru(name)) for name in find_function_names(string)] for path2 in paths: #must apply in path apply_to_file(path2, lambda s: replace_words(tuples, s)) if __name__ == "__main__": paths = sys.argv[2:] if len(sys.argv) <= 2: pass elif sys.argv[1] == "blank": for path in paths: apply_to_file(path, set_blanks_lines) elif sys.argv[1] == "names": set_function_names_loweru(paths)