Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import glob, os, re
- def convert(name):
- s1 = re.sub('(.)([A-Z][a-z]+)', r'1_2', name)
- return re.sub('([a-z0-9])([A-Z])', r'1_2', s1).lower()
- if __name__ == '__main__':
- dir = 'D:......'
- os.chdir(dir)
- def_list = []
- for file in glob.glob("*.py"):
- f = open(file)
- for line in f:
- wostrip = line.lstrip()
- if wostrip.startswith('def'):
- method_name = wostrip[wostrip.find(' ') + 1:wostrip.find('(')]
- if method_name != convert(method_name):
- def_list.append((method_name, convert(method_name)))
- end_list = list(set(def_list))
- end_list.sort(key=lambda tup: tup[0])
- for def_ in end_list:
- old_name = def_[0] # старые имена
- new_name = def_[1] # новые имена
- filelist = ['filename01', 'filename02']
- for filename in filelist:
- with open (filename, 'r') as f:
- old_data = f.read()
- names_map = get_method_names_for_replacement(old_data)
- new_data = old_data
- for old_name in names_map:
- new_data = new_data.replace(old_name, names_map[old_name])
- with open (filename, 'w') as f:
- f.write(new_data)
Add Comment
Please, Sign In to add comment