364,111 Members | 2030 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Python 3 writing in excel

Mike Dean
P: 2
I'm kind of new programming, and I have learnt something in python. So, I want to creat a program, which adds data to an excel file. Each time a run it, it should creat a new colunm and type the information x,y,z,w which is asked, hope the print helps:



Expand|Select|Wrap|Line Numbers
  1. import csv
  2. day=str(intput("day?"))
  3. x=int(input("question1?"))
  4. y=int(input("question2?"))
  5. z=int(input("question3?"))
i stucked here....

Thanks for your time, Mike
Jan 24 '12 #1

✓ answered by bvdet

To write the data to a file:
Expand|Select|Wrap|Line Numbers
  1. >>> day = "Friday"
  2. >>> x = 1
  3. >>> y = 2
  4. >>> z = 3
  5. >>> f = open("data.csv", "w")
  6. >>> f.write(",".join([str(item) for item in (day,x,y,z)]))
  7. >>> f.close()
That creates a file with 4 columns on one row. If you want one column with 4 rows:
Expand|Select|Wrap|Line Numbers
  1. >>> f.write("\n".join([str(item) for item in (day,x,y,z)]))
Share this Question
Share on Google+
3 Replies


bvdet
Expert Mod 2.5K+
P: 2,509
To write the data to a file:
Expand|Select|Wrap|Line Numbers
  1. >>> day = "Friday"
  2. >>> x = 1
  3. >>> y = 2
  4. >>> z = 3
  5. >>> f = open("data.csv", "w")
  6. >>> f.write(",".join([str(item) for item in (day,x,y,z)]))
  7. >>> f.close()
That creates a file with 4 columns on one row. If you want one column with 4 rows:
Expand|Select|Wrap|Line Numbers
  1. >>> f.write("\n".join([str(item) for item in (day,x,y,z)]))
Jan 25 '12 #2

Mike Dean
P: 2
I have saved a excell file named data in python's folder, but he's not writing there...

I have python 3 installed on my pc, do I have to install in module?
Jan 25 '12 #3

bvdet
Expert Mod 2.5K+
P: 2,509
In order to write to a new excel file, you will need module xlwt.
Jan 25 '12 #4

Post your reply

Help answer this question



Didn't find the answer to your Python question?

You can also browse similar questions: Python