File module issues with excel format

Question:

My goal is to write result into single excel file, here is simple code that I tried:

import numpy_financial as npf
Present = 2000
period = 20
rate = 0.12
pmt = abs(npf.pmt(rate/12,period*12,Present))
print(pmt) 
import csv
file = open("Result.xlsx",'w')
file = csv.writer(file)
file.writerow([pmt])

As an outcome, Result.xlsx was created, but I can’t open it. If I change xlsx extension to csv, then it works fine. I know that there is another library called xlsxwriter, but just for shake of curiosity, does csv module supports xlsx-extensions?

Or am I missing something?

Asked By: neural science

||

Answers:

No, the csv module does not support xlsx extensions. Here is a quote from the documentation I linked:

The csv module implements classes to read and write tabular data in
CSV format

The documentation does not mention support for writing xlsx.

Answered By: Marcelo Paco
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.