Guest User

Untitled

a guest
Feb 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import glob, os, re
  2.  
  3. def convert(name):
  4. s1 = re.sub('(.)([A-Z][a-z]+)', r'1_2', name)
  5. return re.sub('([a-z0-9])([A-Z])', r'1_2', s1).lower()
  6.  
  7.  
  8. if __name__ == '__main__':
  9. dir = 'D:......'
  10. os.chdir(dir)
  11. def_list = []
  12. for file in glob.glob("*.py"):
  13. f = open(file)
  14. for line in f:
  15. wostrip = line.lstrip()
  16. if wostrip.startswith('def'):
  17. method_name = wostrip[wostrip.find(' ') + 1:wostrip.find('(')]
  18. if method_name != convert(method_name):
  19. def_list.append((method_name, convert(method_name)))
  20. end_list = list(set(def_list))
  21. end_list.sort(key=lambda tup: tup[0])
  22. for def_ in end_list:
  23. old_name = def_[0] # старые имена
  24. new_name = def_[1] # новые имена
  25.  
  26. filelist = ['filename01', 'filename02']
  27. for filename in filelist:
  28. with open (filename, 'r') as f:
  29. old_data = f.read()
  30. names_map = get_method_names_for_replacement(old_data)
  31. new_data = old_data
  32. for old_name in names_map:
  33. new_data = new_data.replace(old_name, names_map[old_name])
  34. with open (filename, 'w') as f:
  35. f.write(new_data)
Add Comment
Please, Sign In to add comment