Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What user do python scripts run as in windows? [duplicate]

I'm trying to have python delete some directories and I get access errors on them. I think its that the python user account doesn't have rights?

WindowsError: [Error 5] Access is denied: 'path' 

is what I get when I run the script.
I've tried

shutil.rmtree   os.remove   os.rmdir 

they all return the same error.

like image 210
DevelopingChris Avatar asked Jul 31 '09 17:07

DevelopingChris


People also ask

Can Python scripts run on Windows?

On Windows, the standard Python installer already associates the . py extension with a file type (Python. File) and gives that file type an open command that runs the interpreter ( D:\Program Files\Python\python.exe "%1" %* ). This is enough to make scripts executable from the command prompt as 'foo.py'.

How do I run a Python script from command line in Windows 10?

Enter the "python" command and your file's name. Type in python file.py where file is your Python file's name. For example, if your Python file is named "script", you would type in python script.py here.

How do I run a Python script in the background Windows?

If you want to run any Python script in Background in Windows operating System then all you are required to do is to rename the extension of your existing Python script that you want to run in background to '. pyw'.

Where can I run Python code?

To run the Python code, we can use the Python interactive session. We need to start Python interactive session, just open a command-line or terminal in start menu, then type in python, and press enter key. Here is the example of how to run Python code using interactive shell.


1 Answers

We've had issues removing files and directories on Windows, even if we had just copied them, if they were set to 'readonly'. shutil.rmtree() offers you sort of exception handlers to handle this situation. You call it and provide an exception handler like this:

import errno, os, stat, shutil  def handleRemoveReadonly(func, path, exc):   excvalue = exc[1]   if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES:       os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) # 0777       func(path)   else:       raise  shutil.rmtree(filename, ignore_errors=False, onerror=handleRemoveReadonly) 

You might want to try that.

like image 51
ThomasH Avatar answered Sep 21 '22 16:09

ThomasH