I want to write 2D below to a txt file called readme.txt, but I keep on receiving error.
report_storage = [
[' ', '| G02 ', '| G05 ', '| G07 ', '| G08 ', '| G10 ', '| G25 '],
['------', '|------', '|------', '|------', '|------', '|------', '|------'],
['P001 ', '| 1 ', '| 0 ', '| ', '| -- ', '| 1 ', '| 0 '],
['P067 ', '| 1 ', '| 1 ', '| 0 ', '| ', '| -- ', '| 1 '],
['P218 ', '| 0 ', '| 1 ', '| 1 ', '| ', '| ', '| 1 '],
['P101 ', '| 0 ', '| 0 ', '| 1 ', '| 1 ', '| -- ', '| 1 '],
['P456 ', '| 1 ', '| 1 ', '| ', '| 1 ', '| ', '| 0 '],
['------', '|------', '|------', '|------', '|------', '|------', '|------']
]
My code:
with open('readme.txt', 'w') as f:
f.write(report_storage)
My code Output:
Traceback (most recent call last):
File "D:\projects\FinalCodingChallenge\test4.0.py", line 70, in <module>
f.write(report_storage)
TypeError: write() argument must be str, not list
My aim is to get the result below to appear on readme.txt
| G02 | G05 | G07 | G08 | G10 | G25
------|------|------|------|------|------|------
P001 | 1 | 0 | | -- | 1 | 0
P067 | 1 | 1 | 0 | | -- | 1
P218 | 0 | 1 | 1 | | | 1
P101 | 0 | 0 | 1 | 1 | -- | 1
P456 | 1 | 1 | | 1 | | 0
------|------|------|------|------|------|------