Advertisement
mgaikema

Snake case to camel case

Jul 19th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # https://stackoverflow.com/a/19053800/5415895
  2. def to_camel_case(snake_str):
  3.     components = snake_str.split('_')
  4.     # We capitalize the first letter of each component except the first one
  5.     # with the 'title' method and join them together.
  6.     return components[0] + "".join(x.title() for x in components[1:])
  7.  
  8. def main():
  9.     with open('temp1.txt') as f:
  10.         f2 = open("temp2.txt", 'w')
  11.         data = f.readlines()
  12.         for d in data:
  13.             item = d.split(',')
  14.             for i in item:
  15.                 # https://stackoverflow.com/a/899176/5415895
  16.                 f2.write("%s\n" % to_camel_case(i))
  17.  
  18. if __name__ == "__main__":
  19.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement