Python: Write a list of tuples to a file

前端 未结 6 1948
野性不改
野性不改 2020-12-13 10:11

How can I write the following list:

[(8, \'rfa\'), (8, \'acc-raid\'), (7, \'rapidbase\'), (7, \'rcts\'), (7, \'tve-announce\'), (5, \'mysql-im\'), (5, \'teln         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 10:28

    import csv
    with open(, "w") as the_file:
        csv.register_dialect("custom", delimiter=" ", skipinitialspace=True)
        writer = csv.writer(the_file, dialect="custom")
        for tup in tuples:
            writer.write(tup)
    

    The csv module is very powerful!

提交回复
热议问题