I use the following code to get a list of files and return the list with linebreaks in-between each item. What I am trying to do is add a checkbox to each item but string.join only allows 2 arguments.
This is what I’ve tried that produces the error TypeError: join() takes at most 2 arguments (3 given):
listfiles = os.listdir('my_path')
col_list = string.join('<input type="checkbox" />', listfiles, '</br>')
How should I go about formatting my list of files so that each line has a checkbox as well as a line break? Thanks!
This is a lesson on reading error messages. Some are cryptic and understandably difficult to follow up on. This one is fairly clear: You’re passing three arguments to a function that takes only two. You can always check the documentation for standard library functions and methods in the Python Documentation, or at the command prompt using the
help()function on any object. For examplehelp(string.join).Don’t use the
stringmodule for this however, as that usage is deprecated. Strings have a built-in.join()method.You’re looking for