Alex
Alex

Reputation: 59

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.

Upvotes: 0

Views: 43

Answers (1)

Reblochon Masque
Reblochon Masque

Reputation: 36662

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.

Upvotes: 1

Related Questions