#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15

    Writing output to Excel sheet


    Hello,

    I'm able to use a python script to write an output to an MS Excel sheet. But the second time I run the same script, it gives me permission error:

    Code:
        output= open("C:\Documents and Settings\Sam\Desktop\L24.xls","w")
    IOError: [Errno 13] Permission denied: 'C:\\Documents and Settings\\Sam\\Desktop\\L24.xls'
    PS. Here I have used the # buttons as was mentioned in one of the "How to post messages" threads, but still when I use preview, the indentation is not conserved.
    Last edited by netytan; October 4th, 2004 at 03:01 PM.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,645
    Rep Power
    4248
    This error indicates that something else already has the file open. I'm guessing that you have the spreadsheet already open in Excel or something, or perhaps it is a previous running instance of the program which hasn't been killed off yet. Check your Task Manager to be certain.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15
    Thanks alot, yes the page was open and I was trying to write to it!
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Hey Sam,

    Check out your post by clicking on the Edit button; you should be able to see what's changed, and what you need to do to preserve your indentation in future .

    Anyway, to explain your error. Usually if the file is in use by another program [locked], or you don't have write permission on the file, then Python shouldn't be able to write to the file. For example...

    Mark-Smiths-Computer:~ Mark$ cd desktop
    Mark-Smiths-Computer:~/desktop Mark$ ls -al
    total 32
    drwxrwxrw- 6 Mark Mark 204 4 Oct 20:07 .
    drwxr-xr-x 17 Mark Mark 578 3 Oct 21:52 ..
    -rw------- 1 Mark Mark 6148 3 Oct 21:52 .DS_Store
    -rw-r--r-- 1 Mark Mark 0 4 Sep 08:01 .localized
    -rw-rw-rw- 1 Mark Mark 6 4 Oct 20:06 SomeFile.txt
    Mark-Smiths-Computer:~/desktop Mark$ chmod 111
    Mark-Smiths-Computer:~/desktop Mark$ ls -al SomeFile.txt
    ---x--x--x 1 Mark Mark 6 4 Oct 20:06 SomeFile.txt

    Mark-Smiths-Computer:~/desktop Mark$ python
    Python 2.3 (#1, Sep 13 2003, 00:49:11)
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> fileObject = file('SomeFile.txt', 'w')
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    IOError: [Errno 13] Permission denied: 'SomeFile.txt'
    >>>
    Maybe if you attach the script we could spot the problem. For more info on IOError's you can check out:

    http://docs.python.org/lib/module-exceptions.html

    Mark.
    Last edited by netytan; October 4th, 2004 at 03:37 PM.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo