Created
March 2, 2017 20:59
-
-
Save dtolb/7921f96febd05fe232b6116f08989007 to your computer and use it in GitHub Desktop.
convert comments from camel to snake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def convert_comment_string_to_snake_case(s): | |
| """ | |
| Changes String to from camelCase to snake_case | |
| :param s: String to convert | |
| :rtype: String | |
| :rertuns: String converted to snake_case | |
| """ | |
| # regex = r"(\s+##\s+\'\w+)((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))(\w+\'.+)" | |
| # a = re.compile("(\s+##\s+\'\w+)((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))(\w+\')") | |
| regex = r"(\s+##\s+\"\w+)((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))(\w+\".+)" | |
| #a = re.compile("(\s+##\s+\'\w+)((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))(\w+\')") | |
| # m.group(1)sub(r'_\1', s).lower() | |
| result = re.match(regex, s) | |
| if result: | |
| return result.group(1) + "_" + result.group(2).lower() + result.group(3) + '\n' | |
| else: | |
| return s | |
| with open('bandwidth/catapult/__init__.py') as f: | |
| with open('out2.py', 'w') as e: | |
| for line in f: | |
| e.write(convert_comment_string_to_snake_case(line)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment