473,326 Members | 2,337 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,326 software developers and data experts.

writing to excel

Gents (and ladies)...

I'm trying to write data to an excel file while using python 2.4 on a PC running XP...

I can do the very basic of putting data in a txt file, when I provide the data. However...

With help from some of you I've writen a basic Web scrape that goes out and gets a number from a Web site. Is there a way to have my file write the results of the scrape, i feel as if there must be.

What i'm trying so far, with no avail is:

>>> writer = csv.writer(open("some.csv", "wb"))
>>> writer.writerows(scrape.findall(results))

This is wrong for a ton of reason i'm sure. All it gives me is a file named "Some" with the 1st and only sheet called "some"

I was hoping that in the 2nd line ...>>> writer.writerows(scrape.findall(results))
would tell it to take the data collected by my scrape and put it in some.csv.

it of course, does not.

if i type print writer.writerows(scrape.findall(results)) it will return the number I want.

any thougths, suggestions, riducles?

pc
Apr 9 '07 #1
2 3855
bvdet
2,851 Expert Mod 2GB
Gents (and ladies)...

I'm trying to write data to an excel file while using python 2.4 on a PC running XP...

I can do the very basic of putting data in a txt file, when I provide the data. However...

With help from some of you I've writen a basic Web scrape that goes out and gets a number from a Web site. Is there a way to have my file write the results of the scrape, i feel as if there must be.

What i'm trying so far, with no avail is:

>>> writer = csv.writer(open("some.csv", "wb"))
>>> writer.writerows(scrape.findall(results))

This is wrong for a ton of reason i'm sure. All it gives me is a file named "Some" with the 1st and only sheet called "some"

I was hoping that in the 2nd line ...>>> writer.writerows(scrape.findall(results))
would tell it to take the data collected by my scrape and put it in some.csv.

it of course, does not.

if i type print writer.writerows(scrape.findall(results)) it will return the number I want.

any thougths, suggestions, riducles?

pc
The data may be in the buffer and has not been written yet. It's a good practice to explicitly create a file object, pass to the writer instance, and close the file which forces the data to be written.
Expand|Select|Wrap|Line Numbers
  1. import csv
  2.  
  3. dataList = [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0],\
  4.            [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 30.0, 30.0, 30.0, 30.0], \
  5.            [0.0, 0.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 30.0, 30.0],\
  6.            [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0]
  7.  
  8. fn = r'H:\TEMP\temsys\some.csv'
  9. f = open(fn, 'wb')
  10. w = csv.writer(f)
  11.  
  12. w.writerows(dataList)
  13. f.close()
Apr 9 '07 #2
ghostdog74
511 Expert 256MB
here's another way, but it generates to excel straightaway, making use of external Python module, called pyXLWriter . A simple example on how to use it.
Expand|Select|Wrap|Line Numbers
  1. import pyXLWriter as xl
  2. workbook = xl.Writer("test.xls")
  3. worksheet = workbook.add_worksheet('Test')
  4. datalist = [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0] #eg
  5. worksheet.write('A1',datalist[0]) #write 0.0 into cell A1
  6. worksheet.write('B1',datalist[1]) #writer 5.0 into cell B1 and so on
  7. .....
  8. worksheet.write('K1',datalist[10])
  9. workbook.close()
  10.  
after running script, test.xls will be produced. This is of course if you don't mind installing modules to your environment
Apr 10 '07 #3

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

Similar topics

8
by: Deepa | last post by:
I am writing a console app in c# wherein am converting a dataset into a CSV file. It works fine. But I have some values in the dataset which have a comma within(eg. A,B,C). When I view the CSV file...
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...
2
by: bob | last post by:
My program copys things from a word document and puts them into an excel spreadsheet. The problem I have though is these annoying symbols that appear in place of spaces in the text after Ive...
3
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet...
1
by: RahimAsif | last post by:
I am designing a data acquisition program that peridically collects data from a panel and writes to a file. The way I am doing it right now, every time I have data from the panel, I open the file,...
0
by: shintu | last post by:
Hallo, I am trying to write french accented characters é è ê in Excel worksheet using my perl script , But I am stuck here as I couldnt find a way of writing it !: My code: use strict;...
3
by: thanawala27 | last post by:
Hi, I had problems writing in an existing Excel File. There is an excel file with a worksheet. I would like to open this existing Excel file and add another worksheet and write data into it....
0
by: jpero09 | last post by:
Having some trouble writing out accented characters to an ms-excel type output from my asp.net page (c#). I've tried a few different charsets but every time the è on my page is getting rendered as...
1
by: =?Utf-8?B?ZmhpbGxpcG8=?= | last post by:
We have a code snippet that downloads data to Excel. it is writing row by row. This causes a performance issue. Any ideas on how to speed this up will be appreciated. Please find below an...
20
by: Marin Brkic | last post by:
Hello all, please, let me apologize in advance. English is not my first language (not even my second one), so excuse any errors with which I'm about to embarass myself in front of the general...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.