I'm trying to write a helper function to help me generate new file with function definition. Here are part of the code:
def new_function_file(file_name, fun_name, arguments):
f = open(file_name + ".py", 'w')
f.write("\tdef " + fun_name + str(("self", ) + arguments) + ":\n")
new_leetcode_file("testfile", "test", ("arr1", "arr2"))
However, this would generate "def test('self', 'arr1', 'arr2'):" in testfile.py. I was wondering how to properly parse the arguments without single quote generated?
str(("self", ) + arguments) + ":\n")If you get rid of thestr(and closing), you are creating a tuple with("self", )That means the expression("self", ) + argumentswill return a tuple. Thenstrgives you a string representation of that tuple, which is why you get the parentheses in your output.