Python 3 writing in excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Dean
    New Member
    • Jan 2012
    • 2

    Python 3 writing in excel

    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:

    Code:
    import csv
    day=str(intput("day?"))
    x=int(input("question1?"))
    y=int(input("question2?"))
    z=int(input("question3?"))
    i stucked here....

    Thanks for your time, Mike
    Last edited by bvdet; Jan 25 '12, 04:45 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    To write the data to a file:
    Code:
    >>> day = "Friday"
    >>> x = 1
    >>> y = 2
    >>> z = 3
    >>> f = open("data.csv", "w")
    >>> f.write(",".join([str(item) for item in (day,x,y,z)]))
    >>> f.close()
    That creates a file with 4 columns on one row. If you want one column with 4 rows:
    Code:
    >>> f.write("\n".join([str(item) for item in (day,x,y,z)]))

    Comment

    • Mike Dean
      New Member
      • Jan 2012
      • 2

      #3
      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?

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        In order to write to a new excel file, you will need module xlwt.

        Comment

        Working...