By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

Python 3 writing in excel

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,851
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

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,851
In order to write to a new excel file, you will need module xlwt.
Jan 25 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.