我有一个写在文件中的书籍列表(每本书都是一行,它有多个属性除以,
,最后一个属性是True或False),然后使用
list_of_books = open('books'.txt').read().split()
我必须把真改假,反之亦然, 有什么办法吗
列表示例
['qwe,rty,1999,1231231231234,Drama,1000,1,True',
'rty,asd,1900,2342342342345,Fantasy,1000,4,True',
'tui,fgh,2009,4564564564567,Horror,900,5,True']
如果您知道布尔值总是在末尾,那么您可以简单地更改字符串的内容,如下所示:
或者,可以使用split()来完成
相关问题 更多 >
编程相关推荐