Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to store a function parameter to an excel file

I am trying to store a function parameter ‘n’ to an excel file however I receive an error:

AttributeError: 'int' object has no attribute 'to_excel'

I have a function that takes:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def test(alpha,a,x,y,n):

I need to store n (which is a single integer) in an excel file where I tried:

n.to_excel('n.xlsx')

However I receive the error as mentioned before. I tried to make an empty DataFrame and write n into the array which allows me to run the code however there is no value in the file. I have printed n in the function and it returns the integer so a bit confused on why I cannot save this value to an excel file?

>Solution :

You will need to install library openpyxl which can create and modify excel. The final code will look something like this:

from openpyxl import Workbook

def test(alpha,a,x,y,n):
    wb = Workbook()
    ws = wb.active

    ws.append([n])

    wb.save("sample.xlsx")

test(alpha=3, a = 4, x = 10, y = 15, n = 100)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading