Inserting a row into excel file

3,177 views
Skip to first unread message

Bidamin

unread,
Feb 4, 2009, 3:19:34 PM2/4/09
to python-excel
I've been searching through goolgle and this group and cant seem to
get a strait answer:

I am trying to write a python program that will either change any
number of cells in a user given row, or insert a new row if it does
not exist.
I've been using xlrd to do all of the searching required, but it seems
that an xlrd workbook is not compatible with an xlwt workbook

is there a way to do this? do I need to learn xlutils also?

Daniel Burke

unread,
Feb 4, 2009, 10:51:53 PM2/4/09
to python...@googlegroups.com
Neither modules modify xls files. You can use xlrd to read the entire file, and xlwt to write a new file with the changes you need. AFAIK xlutils provides some very usefull helper functions to the above, but I haven't used it yet. By far the easiest way to accomlish your goal is through COM, the syntax for inserting a line is...

xlApp.ActiveSheet.Range(Cells(2,2), Cells(2,2)).EntireColumn.Insert(-4161)

For some reason insert only works on the EntireColumn of a Range, not the EntireColumn of a Cell, maybe I didn't have enough sleep at the time, although I was dealing with Excel COM, so I was clearly mentally unstable at the time.
-4161 is one of many magical constants that Excel uses. IIRC I found it on msdn, somewhere it had the listing of a .h file that listed them all. This particular constant in this particualr context means "to the left", the default is "to the right" (which is any value other than -4161, including no value at all).

I uploaded a file to the files area of this google group that should have enough of an example to get you going. Of course, if you're not writting on windows, then this is not an option and you are truly blessed.

Bidamin

unread,
Feb 5, 2009, 9:58:52 AM2/5/09
to python-excel
Is there any talk of developing a module to do this? Or expanding
xlutils?

and thank you for your help. Do you think it would be easier to just
run copy the xlrd workbook
to the xlwt workbook instnaces? and them modify the xlwt before
saving? and toy around w/ xlutils?
or would u suggest I learn COM and use that? Is the xlrd easy
compatable with COM?

sorry for so many questions.

On 4 Feb, 22:51, Daniel Burke <dan.p.bu...@gmail.com> wrote:
> Neither modules modify xls files. You can use xlrd to read the entire file,
> and xlwt to write a new file with the changes you need. AFAIK xlutils
> provides some very usefull helper functions to the above, but I haven't used
> it yet. By far the easiest way to accomlish your goal is through COM, the
> syntax for inserting a line is...
>
> xlApp.ActiveSheet.Range(Cells(2,2), Cells(2,2)).EntireColumn.Insert(-4161)
>
> For some reason insert only works on the EntireColumn of a Range, not the
> EntireColumn of a Cell, maybe I didn't have enough sleep at the time,
> although I was dealing with Excel COM, so I was clearly mentally unstable at
> the time.
> -4161 is one of many magical constants that Excel uses. IIRC I found it on
> msdn, somewhere it had the listing of a .h file that listed them all. This
> particular constant in this particualr context means "to the left", the
> default is "to the right" (which is any value other than -4161, including no
> value at all).
>
> I uploaded a file to the files area of this google group that should have
> enough of an example to get you going. Of course, if you're not writting on
> windows, then this is not an option and you are truly blessed.
>

Daniel Burke

unread,
Feb 5, 2009, 11:13:16 AM2/5/09
to python...@googlegroups.com
Don't learn COM, it's painful, and only useful in a very limited context. If you grab the file "excel-formatting-examples.py" from here...

http://groups.google.com/group/python-excel/files?hl=en-GB


COM vs xlwt & xlrd

COM pros
COM is really easy.
Lots of documentation.
You can modify xls files.
It fully supports everything.
Its very simple, the Excel COM API was designed for VBA coders, so we're really talking lowest common denominator here.
You can modify existing files.
Because it's so slow, its easy to debug, because you can actually see Excel doing its thing. Even on a 3.3Ghz Core 2 Duo.

COM cons
Its fickle.
You can't do anything with Excel while it's running.
Its very very slow (most simple things take 5-10 seconds, but I've done very layout heavy xls files that can take minutes)
It only works on windows with Excel installed.
Not much python specific documentation.
Can only have one instance.

xlwt pros
It's really fast. I've never done anything that takes a human perceptable timeframe.
It doesnt need windows or excel.
You can have as many instances as you care for (ie. web servers)
It works every single time.
Simple layout is really easy.
Files output are between 2 and 10 times smaller.
You can redirect the output to a StringIO instead of a file (great for web servers)
John Machin apparently spends 30 hours a day on this list, so questions get answered quickly.

xlwt cons
It doesn't support everything (of note to me, array formulas)
Doing layout heavy things is really painful.
It's very easy to make xls files that Excel doesnt like. (its also very easy to avoid doing this, and progess is being made rapidly to make this impossible)
You can't modify existing files.
No autosize (which is fair enough, but annoying none the less)
Documentation is a bit thin.

xlrd pros
all the good things about xlwt.
doesn't need documentation, its really easy. (there are some examples out there though)
interface is similar to the COM interface (that sounds like an insult, but the COM interface to Excel is very clean, if a bit java-ish with its objects being children of objects ad nausium)
Again, John has found a way to survive without sleep. He is here for the community.

xlrd cons
are there any? Oh it can't handle array formulas (who cares)

xlutils.
I haven't had the time to check it out yet, but it is certainly appreciated on this list. I know it gets past some of the limitations I've mentioned here, specifically which ones I am unsure of. Someone else could be helpful here.


These are the things to consider that I am aware. I'd have to recommend avoiding COM like the plague. The idea behind COM is pretty good, but the implementation and use is really nasty. Python does a great job of hiding the nasty, but I can almost guarantee that any COM code you write now won't work in 1-2 years time. MS loves releasing patches that break things.

If you have really complicated spreadsheets (array formulas, graphs, data connections, etc) you have to deal with, COM is the only option.

If your not using array formulas, graphs and data connections, or if speed is an issue use xl*. Sometimes it may seem like xl* requires a lot more code than COM, thats because you're doing it wrong, come back here and ask a question. It's worth spending several hours to try to figure out if xl* can do it.

Hopefully one of the xlutils folk will post something like this here about xlutils :-)

Bidamin

unread,
Feb 5, 2009, 11:36:17 AM2/5/09
to python-excel
thanks for that I'm gonna look up com and have a look, but while im
doing that, how does this look for a copy function that edits row R,
(pulled from a text file)
the first line of the text file is the row, while the rest of the
lines are the data

def EDIT(n):
bk = n.sheet_by_index(0)
f = open('DATAFILE','r')
f = f.readlines()
m = xlwt.Workbook()
m.add_sheet('1')

for y in range(len(bk.col(0))):
if(y == f[0]):
for x in range(1:len(f)-1):
m.get_sheet(0).write(y,x,f[x])
else:
for x in range(len(bk.row(y))):
m.get_sheet(0).write(y,x,bk.row(y)[x].value)

John Machin

unread,
Feb 5, 2009, 4:02:42 PM2/5/09
to python...@googlegroups.com
On 6/02/2009 3:36 AM, Bidamin wrote:
> thanks for that I'm gonna look up com and have a look, but while im
> doing that, how does this look for a copy function that edits row R,
> (pulled from a text file)
> the first line of the text file is the row, while the rest of the
> lines are the data

The concept is mostly fine. You either assume that all cells in the
changed row are to be text cells or omit details of how you would ensure
that a line containing '123.45' would be written to the output worksheet
as a number cell.

However the execution is not mostly fine. In particular:
(1) apart from x and y, the names used make it look like a deliberate
obfuscation exercise
(2) there's a syntax error
(3) there are three logic errors

If you have any questions about the detailed critique and rewrite below,
please don't hesitate to ask.

HTH,
John

8<---

# Dramatis personae, in order of first appearance:

# EDIT function
# n xlrd.Book instance
# bk xlrd.Sheet instance #ARGH
# f file instance IMMEDIATELY RE-USED as list of strings # AARRGGHH
# m xlwt.Workbook instance
# <anon.> xlwt.Worksheet instance # AAARRRGGGHHH
# y int, used as row index
# x int, used as column index

def EDIT(n):
bk = n.sheet_by_index(0)
f = open('DATAFILE','r')
f = f.readlines()
m = xlwt.Workbook()
m.add_sheet('1')

for y in range(len(bk.col(0))): #### use the worksheet's nrows
attribute!
if(y == f[0]): #### will fail; 123 != "123\n"
# for x in range(1:len(f)-1): #### syntax error
# for x in range(1, len(f)-1): #### logic errors
# m.get_sheet(0).write(y,x,f[x])
# The above code writes data starting on column B and omits
last item
for x in range(1, len(f)):
m.get_sheet(0).write(y, x - 1, f[x])


else:
for x in range(len(bk.row(y))):
m.get_sheet(0).write(y,x,bk.row(y)[x].value)

# [untested]

def edit_workbook(rd_book, datafile_path, new_workbook_path):
rd_sheet = rd_book.sheet_by_index(0)
f = open(datafilename,'r')
target_rowx = int(f.readline())
assert 0 <= target_rowx < rd_sheet.nrows
replacement_values = [line.rstrip() for line in f]
# Purpose of using rstrip is to remove '\n'
# (and any other trailing whitespace)
f.close()
wt_book = xlwt.Workbook()
wt_sheet = wt_book.add_sheet(rd_sheet.name)
for rowx in range(rd_sheet.nrows):
if rowx == target_rowx:
source = replacement_values
else:
source = rd_sheet.row_values(rowx)
for colx, value in enumerate(source):
wt_sheet.write(rowx, colx, value)
wt_book.save(new_workbook_path)
8<---

Chris Withers

unread,
Feb 6, 2009, 11:25:51 AM2/6/09
to python...@googlegroups.com
Bidamin wrote:
> Is there any talk of developing a module to do this? Or expanding
> xlutils?

xlutils.copy will likely help you a lot, when it arrives.

However, for inserting rows, you likely want xlutils.filter, which is
here already...

> and thank you for your help. Do you think it would be easier to just
> run copy the xlrd workbook
> to the xlwt workbook instnaces? and them modify the xlwt before
> saving?

That's exactly what xlutils.copy will do in one function call...

> or would u suggest I learn COM and use that? Is the xlrd easy
> compatable with COM?

Apples and oranges, they can both work with .xls data, but not at the
same time ;-)

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

Bidamin

unread,
Feb 6, 2009, 1:31:08 PM2/6/09
to python-excel
ok so sometimes when i try to do xlwt.write(....) it will give me this
error

IOError: [Errno 22] invalid mode ('wb') or filename: 'FILE.xls'

i understand the error well enough, but it shows up at inconsistent
times. Sometimes if I alter the path to be

'C:\......\FILE.xls'

it works, but not always, is there some specific way i should set the
save path? all i want it to do is save it over the origninal, and
workbook.name doesnt exist as far i know

JimM

unread,
Feb 6, 2009, 10:07:18 AM2/6/09
to python-excel
I have used xlrd to read data out of Excel and write it to a
database.

I looked into xlrd/xlwt to try and use it to combine two different
spreadsheets into one, but because of the required complexity of the
resulting spreadsheet (Many graphs and the like), I had to do COM.
COM IS SOOOOO SLOW. But it does accomplish exactly what I need it to
accomplish, exactly how it needs to be accomplished because it
functions essentially as just a macro into Excel.

Thank you for having this discussion because now that I think about
the Pros/Cons I think I can rewrite my code to use xlrd to read from
one spreadsheet and then COM to write to the final one in a much
smarter manner (and faster too because I won't be doing the COM thing
twice).

Thanks guys
> > > > is there a way to do this? do I need to learn xlutils also?- Hide quoted text -
>
> - Show quoted text -

John Machin

unread,
Feb 6, 2009, 4:10:04 PM2/6/09
to python...@googlegroups.com
On 7/02/2009 5:31 AM, Bidamin wrote to a thread called "Inserting a row
into excel file":

New topic, new subject, OK?

> ok so sometimes when i try to do xlwt.write(....) it will give me this
> error
>
> IOError: [Errno 22] invalid mode ('wb') or filename: 'FILE.xls'

That would be quite astonishing. There is no write function exposed at
the top level of the package. Output is done only in response to a
Workbook.save_as(file_path) call.

>
> i understand the error well enough, but it shows up at inconsistent
> times. Sometimes if I alter the path to be
>
> 'C:\......\FILE.xls'
>
> it works, but not always, is there some specific way i should set the
> save path? all i want it to do is save it over the origninal, and
> workbook.name doesnt exist as far i know

What is "workbook.name"?

So that we can help you, you will have to divulge information like:
1. Windows: what version, what service pack
2. Python: what version
3. xlwt: the released version? If not, what svn revision?
4. The full traceback that is printed when such a problem happens.
Copy/paste, *don't* retype anything. We need to see *exactly* what is
there; "FILE" is useless. Also we need to see exactly where in xlwt the
error is being raised.
5. Is the path that you are specifying on a network share, or anything
else that's not a normal plain vanilla path into which you can save
files? Assuming the problematic path is c:\foo\bar.xls, can you use
Notepad to save a file called c:\foo\bar.txt?
6. "Alter the path"?? Is the file path hardcoded in your script? Please
send me a copy of your script.
7. What is your locale? Are there any non-ASCII characters in the paths
that fail? Are there any invalid characters, like "?"?

Bidamin

unread,
Feb 6, 2009, 4:42:02 PM2/6/09
to python-excel

to answer your questions:

im using windows xp, I'm guessing the most up to date version (work
computer)
python 2.6
xlwt release version
the full trace back
--------------------------------------------------------
Traceback (most recent call last):
File "C:\Python26\Lib\XLP3.py", line 397, in onEdit
self.EDIT(file_name)
File "C:\Python26\Lib\XLP3.py", line 377, in EDIT
new_book.save(new_book_path.__str__())
File "C:\Python26\lib\site-packages\xlwt\Workbook.py", line 501, in
save
doc.save(filename, self.get_biff_data())
File "C:\Python26\lib\site-packages\xlwt\CompoundDoc.py", line 507,
in save
f = open(file_name_or_filelike_obj, 'wb')
IOError: [Errno 22] invalid mode ('wb') or filename: 'testy.xls'
-----------------------------------------------------------

the file it self is called "testy.xls" and its saved in the c: drive,
the path for the file is
C:\Python26\Lib\testy.xls

this is the save script
file_name = 'testy.xls'
self.EDIT(file_name)

i had a variable one but it wasnt working, so for development purposes
im using this.
i wont be able to respond to any input until sunday, so there is not
rush, but if you need any more information,
i will be able to send it then

thanks

John Machin

unread,
Feb 6, 2009, 5:46:11 PM2/6/09
to python...@googlegroups.com
On 7/02/2009 8:42 AM, Bidamin wrote:
>
> to answer your questions:

*Some* of the questions. Notably you didn't answer the one about whether
you can use Notepad to save a .txt file in the same place.

> im using windows xp, I'm guessing the most up to date version (work
> computer)

Don't guess; it is pointless and irritates the [expletive deleted] out
of people who are trying to help you.

> python 2.6

2.6.0 or 2.6.1?

> xlwt release version
> the full trace back
> --------------------------------------------------------
> Traceback (most recent call last):
> File "C:\Python26\Lib\XLP3.py", line 397, in onEdit
> self.EDIT(file_name)
> File "C:\Python26\Lib\XLP3.py", line 377, in EDIT
> new_book.save(new_book_path.__str__())

Why do you have .__str__() there???
If you put this line in
print "waste of keystrokes:", new_book_path.__str__() == new_book_path
what is printed?

> File "C:\Python26\lib\site-packages\xlwt\Workbook.py", line 501, in
> save
> doc.save(filename, self.get_biff_data())
> File "C:\Python26\lib\site-packages\xlwt\CompoundDoc.py", line 507,
> in save
> f = open(file_name_or_filelike_obj, 'wb')
> IOError: [Errno 22] invalid mode ('wb') or filename: 'testy.xls'
> -----------------------------------------------------------
>
> the file it self is called "testy.xls" and its saved in the c: drive,
> the path for the file is
> C:\Python26\Lib\testy.xls

Unconfuse me: it's saved there as in "it already exists there", or as in
"there is an attempt to save it there but the attempt fails"?

It is possible that Python has been installed in such a fashion that you
don't have write access to C:\Python26\Lib. Who installed it and what
option was chosen: "everyone" or "myself"? Have you been able to create
any files at all in that folder?

Do you sometimes log on as an administrator and sometimes as an ordinary
user?

In any case, it is not a very good idea at all to be dumping your files
in such a folder. Set up a folder hierarchy for your projects somewhere
well away from installed software.

> this is the save script
> file_name = 'testy.xls'
> self.EDIT(file_name)

That isn't the whole script.

How do you know that C:\Python26\Lib\ is where the save attempt is being
made?

If you insert:
import os
print "current working directory is", repr(os.getcwd())
in front of the line
new_book.save(new_book_path.__str__())
what do you see printed?

Cheers,
John


Daniel Burke

unread,
Feb 6, 2009, 10:49:22 PM2/6/09
to python...@googlegroups.com
COM can be made a lot faster by using ranges, for example

for y,row in enumerate(data):
   for x,item in enumerate(row):
       Cells(y+1, x+1).Value = item

is very very slow, specifically COMDelay * number of items, where COMDelay is usually about half a second.

Sheet.Range( Cells(1,1), Cells(len(data), len(data[0])) ).Values = data

Only takes COMDelay amount of time.
Of course, even with this trick, xlrd/xlwt are orders of magnitude faster.

It can be a bit frustrating at first, as a horizontal row is merely a list/tuple, however a vertical row is a list of single element lists.

Bidamin

unread,
Feb 9, 2009, 10:21:55 AM2/9/09
to python-excel


On 6 Feb, 17:46, John Machin <sjmac...@lexicon.net> wrote:
> On 7/02/2009 8:42 AM, Bidamin wrote:
>
>
>

> Don't guess; it is pointless and irritates the [expletive deleted] out
> of people who are trying to help you.


python 2.6.1
windows xp service pack 2 professional edition

> > xlwt release version
> > the full trace back
> > --------------------------------------------------------



>
> >   File "C:\Python26\lib\site-packages\xlwt\Workbook.py", line 501, in
> > save
> >     doc.save(filename, self.get_biff_data())
> >   File "C:\Python26\lib\site-packages\xlwt\CompoundDoc.py", line 507,
> > in save
> >     f = open(file_name_or_filelike_obj, 'wb')
> > IOError: [Errno 22] invalid mode ('wb') or filename: 'testy.xls'
> > -----------------------------------------------------------
>
> > the file it self is called "testy.xls" and its saved in the c: drive,
> > the path for the file is
> > C:\Python26\Lib\testy.xls
>
> Unconfuse me: it's saved there as in "it already exists there", or as in
> "there is an attempt to save it there but the attempt fails"?
>

the point of my program is that i want to add/del/manipulate files in
an excel spread sheet.
Since I cant open, edit and save one, I need to copy it to a new excel
file. However i also done
want a new file generated each time I hit save so I want it to
overwrite the old one.

I can save text file there, the beginning of my program saves a txt
file there and is re opened later in the program.

> > this is the save script
> >         file_name = 'testy.xls'
> >         self.EDIT(file_name)
>
> That isn't the whole script.
>
> How do you know that C:\Python26\Lib\ is where the save attempt is being
> made?
> If you insert:
>      import os
>      print "current working directory is", repr(os.getcwd())
> in front of the line
>      new_book.save(new_book_path.__str__())
> what do you see printed?
i put the .__str__() because wxpython and xlrd saves data as unicode
and I'm still not sure on the differences between unicode and string,
so I change a lot of them into string just in case and i plan on using
a text box to import the name of the document.. eventually

the current current working directory is 'C:\\Python26\\Lib'

that is were the the attempt is being made because sometimes I can
save it there, and other times I cant.
its not always consistent.

if you want to see my whole EDIT method here you go

*****************************************************************************
'''
EDIT: edits self.BOOK and saves it.
self.BOOK Book curently being worked on
self.reversePriner Changes the data in the txt box self.edit
into a usable format
self.addRow contains the row to be edited
self.addP is either 1 if addP is true, 0 if addP is false
or -1 if addP is not yet called
self.delP is either 1 for true and 0 for false.

*will be fixing *source = self.result* at a later date
'''
def EDIT(self,new_book_path):
bk = self.BOOK.sheet_by_index(0)
new_book = xlwt.Workbook()
new_sheet = new_book.add_sheet(bk.name)
self.reversePrinter(self.edit.GetValue())
target_row = self.addrow.GetValue()
difer = 0
for rowx in range(bk.nrows):
if(self.addP == 1 and rowx == float(target_row)):
self.addP = 0
source = self.result
difer = -1
elif(rowx == float(target_row) and self.delP ==1):
self.delP = 0
difer = 1
break
elif(rowx == float(target_row)):
source = self.result
else:
source = bk.row_values(rowx+difer)
if (self.delP ==1):
pass
else:
for colx, value in enumerate(source):
new_sheet.write(rowx, colx, value)
new_book.save(new_book_path)
*****************************************************************
addP and delP are used to determine if the user wants to add a row or
delete a row.


the current 'new_book_path' is

self.EDIT( 'testy.xls')


John Machin

unread,
Feb 10, 2009, 5:27:45 PM2/10/09
to python...@googlegroups.com
On 10/02/2009 2:21 AM, Bidamin wrote:
>

>
> the current current working directory is 'C:\\Python26\\Lib'
>
> that is were the the attempt is being made because sometimes I can
> save it there, and other times I cant.
> its not always consistent.

With one particular new_book_path, e.g. testy.xls, does it always fail,
never fail, or sometimes fail?

If the story is that with one bunch of paths it always fails, and with
another bunch of paths it never fails, please tell us the two bunches.

Just as an experiment, please try these:

bunch (1) testy.xls, besty..., festy, mesty, nesty
bunch (2) cesty, desty, zesty

> if you want to see my whole EDIT method here you go
>

[snip]

insert here:
print "new_book_path", repr(new_book_path)

> new_book.save(new_book_path)

> the current 'new_book_path' is
>
> self.EDIT( 'testy.xls')
>

When a failure happens, e.g. with 'testy.xls', what happens when you try
this at the Python interactive prompt:
>>> import os; print os.getcwd() # should say 'C:\\Python26\\Lib'
>>> open('testy.xls', 'wb')
>>> open('c:\\Python26\\Lib\\testy.xls', 'wb')
>>> open('c:/Python26/Lib/testy.xls', 'wb')
>>> open(r'c:\Python26\Lib\testy.xls', 'wb')
>>> open('c:\Python26\Lib\testy.xls', 'wb')


Please answer the previously asked question: Is the outcome dependant on
whether you are logged on as an Administrator or not?

Bidamin

unread,
Feb 10, 2009, 6:01:04 PM2/10/09
to python-excel


On 10 Feb, 17:27, John Machin <sjmac...@lexicon.net> wrote:
> On 10/02/2009 2:21 AM, Bidamin wrote:
>
>
>
> > the current current working directory is 'C:\\Python26\\Lib'
>
> > that is were the the attempt is being made because sometimes I can
> > save it there, and other times I cant.
> > its not always consistent.
>
> With one particular new_book_path, e.g. testy.xls, does it always fail,
> never fail, or sometimes fail?
>
> If the story is that with one bunch of paths it always fails, and with
> another bunch of paths it never fails, please tell us the two bunches.
>
> Just as an experiment, please try these:
>
> bunch (1) testy.xls, besty..., festy, mesty, nesty
> bunch (2) cesty, desty, zesty

i tried several different names and and the same result came up, works
for a little while then
i get the error

> When a failure happens, e.g. with 'testy.xls', what happens when you try
> this at the Python interactive prompt:
>   >>> import os; print os.getcwd() # should say 'C:\\Python26\\Lib'
>   >>> open('testy.xls', 'wb')
>   >>> open('c:\\Python26\\Lib\\testy.xls', 'wb')
>   >>> open('c:/Python26/Lib/testy.xls', 'wb')
>   >>> open(r'c:\Python26\Lib\testy.xls', 'wb')
>   >>> open('c:\Python26\Lib\testy.xls', 'wb')

i typed them all in and they all worked except the last one

and i am running on administrator on this computer

John Machin

unread,
Feb 10, 2009, 6:24:59 PM2/10/09
to python...@googlegroups.com
On 11/02/2009 10:01 AM, Bidamin wrote:
>
>
> On 10 Feb, 17:27, John Machin <sjmac...@lexicon.net> wrote:
>> On 10/02/2009 2:21 AM, Bidamin wrote:
>>
>>
>>
>>> the current current working directory is 'C:\\Python26\\Lib'
>>> that is were the the attempt is being made because sometimes I can
>>> save it there, and other times I cant.
>>> its not always consistent.
>> With one particular new_book_path, e.g. testy.xls, does it always fail,
>> never fail, or sometimes fail?

Please answer the question.

>>
>> If the story is that with one bunch of paths it always fails, and with
>> another bunch of paths it never fails, please tell us the two bunches.
>>
>> Just as an experiment, please try these:
>>
>> bunch (1) testy.xls, besty..., festy, mesty, nesty
>> bunch (2) cesty, desty, zesty
>
> i tried several different names and and the same result came up, works
> for a little while then
> i get the error

Do you mean that (for example) you tried testy.xls a few times and at
first it worked (how many times?) and then stopped working and you tried
cesty.xls a few times and at first it worked (how many times?) and
then stopped working?

If not (and perhaps even if so), could you please state what you did and
what the outcome was in a clear and unambiguous fashion e.g.
testy ok
testy ok
testy fail
cesty ok
cesty ok
cesty fail


Daniel Burke

unread,
Feb 10, 2009, 6:26:46 PM2/10/09
to python...@googlegroups.com
Hmm, this is reminding me of a problem I have, I really hope I'm wrong, but what virus scanner are you using?

Can you replicate the problem without a virus scanner loaded?

Bidamin

unread,
Feb 11, 2009, 9:58:59 AM2/11/09
to python-excel
OK i ran the program and tried these names
testy
zesty
besty
cesty
carol

each one 5 times

and didnt get the error. I then opened the excel files I was saving to
and tried it and THEN
i go the error. So i think when i got this error it was when i had the
excel file open. I dont
remember if i had the file open the other times got the error, but i
guess that was the issue
i will keep a better log of what input i am using from now on, in the
event that this error arises
again
thanks

John Machin

unread,
Feb 11, 2009, 6:29:41 PM2/11/09
to python...@googlegroups.com
On 12/02/2009 1:58 AM, Bidamin wrote:
> OK i ran the program and tried these names
> testy
> zesty
> besty
> cesty
> carol
>
> each one 5 times
>
> and didnt get the error. I then opened the excel files I was saving to
> and tried it and THEN
> i go the error. So i think when i got this error it was when i had the
> excel file open. I dont
> remember if i had the file open the other times got the error, but i
> guess that was the issue
> i will keep a better log of what input i am using from now on, in the
> event that this error arises
> again

That sounds like a good idea.

However the error that I would expect if a file with the same path is
open in Excel is *DIFFERENT* ...

IOError: [Errno 13] Permission denied: 'fubar.xls'

Reply all
Reply to author
Forward
0 new messages