Python Programming Tip - How to write function to convert camel case to snake case?
Python Programming Tip - How to write function to convert camel case to snake case?
Today i am going to show How to write function to convert camel case to snake case in python with simple code. I hope you will understand this.
If you have any query you can ask.
i hope you will like it.
import 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()
print convert('JavaBeans')
print convert('JavaStrutsSwing')
OUTPUT
java_beans
java_struts_swing
Follow me at : https://steemit.com/@ahmadhassan
=========================================================
Thanks for reading and always welcome your suggestions :) =========================================================
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by ahmadhassan from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.