Question: Write a python function convert_names(inputf, outputf) where the input file contains one variable name on each line. Each variable name is either camelCase or snake_case.
Write a python function convert_names(inputf, outputf) where the input file contains one variable name on each line. Each variable name is either camelCase or snake_case. If the name is camelCase, the function should convert it to snake_case and vice versa. The function should then write these new variable names to the output file.
def test_convert_variable_names():
# test 1
convert_variable_names("input.txt", "output.txt")
f = open("output.txt", "r")
result = f.readlines()
assert(result == ["all_results ", "totalSum ", "returnList"])
f.close()
# test 2
convert_variable_names("input1.txt", "output1.txt")
f = open("output1.txt", "r")
result = f.readlines()
assert(result == ["varA ", "varB ", "varC ", "new_var_a ", "var_b ", "newVarC"])
f.close()
print("done!")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
