473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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:



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)]))

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

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

Similar topics

3
by: calfdog | last post by:
Hello, I have been doing some experimenting with Automating Internet Explorer for testing. I would like to read from Excel and use the data to set the values of my text boxes on my web forms....
0
by: justin worrall | last post by:
Hi,   I have a very simple python win32 example (gleaned from the O'Reilly book on Win32 programming for Python), of an Excel client with a COM server. Essentially I have three VB buttons -...
3
by: Xiao-Qin Xia | last post by:
I don't like VBA, and want to use python to work with Excel. Does anybody recommend some good documents to begin with? Many thanks, Xiao-Qin
3
by: ian castleden | last post by:
From time to time I see requests for some sort of python MS Excel interface/software. I have written just such software 100% python (works with Jython too! at least it did a year ago). It was...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
1
by: Mike P | last post by:
I'm trying to take some data from an Excel spreadsheet, put it into a dataset, and then update a SQL table with the data. I'm not 100% sure I'm doing this right, can somebody tell me what I'm...
4
by: michael.pearmain | last post by:
Hi Experts, Looking for a very quick bit on of advice on how to make some python code run. I'm a newbie to both VBA and Python, so i apologise if this is very easy but i'm about to tear my hair...
2
by: arvind1083 | last post by:
I need help for writing a excel file. As in one excel file there could be more than one sheets so I want to know how can I give name to different sheets and select a particular sheet for writing or...
3
by: Ray | last post by:
Hi, I'm working on something with mysql and excel. I'm using python and win32com. All major function works, But I have two problems: 1. the output need to do "auto fit" to make it readable. ...
1
by: hippychickhol | last post by:
Hello Basically i am trying to perfrom a load flow analysis in ipsa, but require python to to use it(i have 17000 time instances!). In order to do this, i want to take information (P and Q) out...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.