10 examples of 'python replace space with underscore' in Python

Every line of 'python replace space with underscore' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
23def underscore(word):
24 word = re.sub(r"([A-Z]+)([A-Z][a-z])", r'\1_\2', word)
25 word = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', word)
26 word = word.replace("-", "_")
27
28 return word.lower()
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

20def underscore(name):
21 return re.sub('([A-Z]+)', r'_\1', name).strip('_').lower()
22def underscore(name):
23 return re.sub(r' ', r'_', name).lower()
14def underscore(value):
15 ''' Convert dots to underscore in a string '''
16 return value.replace('.', '_')
241def underscore(string):
242 sanitzed_string = _string_sanity_check(string)
243 replaced = re.sub(r"([A-Z]+)([A-Z][a-z])", r'\1_\2', sanitzed_string)
244 replaced = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', replaced)
245 return replaced.replace("-", "_").lower()
71def underscore_style(c):
72 return c.replace(" ","_").lower()
32def underscore(title):
33 return re.sub(r"(?<=[a-z])(?=[A-Z])", u"_", title).lower()
148@staticmethod
149@not_keyword
150def _underscore(str):
151 return re.sub(r"\s+", "_", str)
24def remove_space(s):
25 return re.sub(r'\n|\r|\s', '', s)
37def withoutLeadingUnderscore( thisName ):
38 if thisName and thisName.startswith("_"):
39 return thisName[1:]
40 else:
41 return thisName

Related snippets