简体   繁体   中英

How to get a String output for lines instead of Tuples?

My code produces an error: How to get a String output for lines instead of Tuples?

def html_lines(file_count, content_in_dictionnary):

table_line = "".join(["<tr> <th> </th><th> ",
                      "</th> <th>".join([key for key in content_in_dictionnary]),
                      "</th></tr> "]),

for x in range(file_count):
    table_line += "".join([
      "<tr><td>Line_number",
      str(x + 1),
      "</td> <td>",
      "</td> <td>".join([content_in_dictionnary[key][x] for key in content_in_dictionnary]),
      "</td> <td></tr>"]),
return table_line

after debugging this section, i'm getting a tuple type on each line while i want a string type.

You have two comma trailing these line of code, remove them:

This one:

table_line = "".join(["<tr> <th> </th><th> ",
                      "</th> <th>".join([key for key in content_in_dictionnary]),
                      "</th></tr> "]),  # <-- here

and that one:

table_line += "".join([
  "<tr><td>Line_number",
  str(x + 1),
  "</td> <td>",
  "</td> <td>".join([content_in_dictionnary[key][x] for key in content_in_dictionnary]),
  "</td> <td></tr>"]),  #<-- here

tuples are defined by a comma placed after a value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM