2017-10-30 9 views
0

私のコードでは、エラー:タプルの代わりに行の文字列出力を取得する方法がありますか?私はstringタイプを希望しながら、タプルではなく行の文字列出力を取得する方法は?

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 

このセクションをデバッグした後、私は、各行のtupleタイプを取得しています。

+1

、)最後の行 – Sayse

+0

'」​​ "]への第二の浮遊コンマを削除し 'と'" "])、 ' – Sayse

答えて

1

あなたは、コードのこれらの行を末尾の2つのカンマを持って、それらを削除します。

をこの1:

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

その1:

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 

タプルが後に置かれ、コンマによって定義されています価値。

+0

はそれを行う私は、このエラーを与えた:TypeError例外:だけ" ではない(タプルを連結することができますユニコード ")をタプル – Alex

+0

hehe、あなたは2つの末尾にカンマがあった、答えを参照してください。 –

+0

これらの2つのカンマは私に頭痛を与えました。 – Alex

関連する問題