Hello world,
I am fighting with what is probably a stupid problem.
In a wxpython GUI, here is a method which must read a file,
and if the file is not correctly formed rename it and create a new file:
(I have removed most of the logic of the code here, so I am not sure
it's going to be helpful)
def makeTree(self):
print 'HERE WE ARE'
f = file(self.__fil ename,'r')
f.close()
from shutil import move
from os.path import join
bakname = self.__filename + '.bak'
print bakname
print f.closed
f.close()
print 'TEST',f.closed
move(self.__fil ename,bakname)
Here is some of the output corresponding to this method
(on cygwin/Windows 2000, with python 2.3.3):
.... in makeTree:
move(self.__fil ename,bakname)
File "e:\Program\Pyt hon\lib\shutil. py", line 171, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: u'C:\\home\\nat asha\\stephane\ \PYTHON
\\Projects\\Scr ipts\\config.xm l'
python -V
Python 2.3.3
I just do not understand what could cause this "permission s denied" for this
file. Any idea of what stupid thing I could have done somewhere in the code
that could cause that ?
Thanks in advance for any suggestion...
Regards,
--
Stephane Ninin 7 13975
"Stéphane Ninin" <st*****@alussi nan.org> writes:
[...] (I have removed most of the logic of the code here, so I am not sure it's going to be helpful)
[...]
Post a short snippet of code that runs and demonstrates the problem.
John
Stéphane Ninin wrote: I just do not understand what could cause this "permission s denied" for this file. Any idea of what stupid thing I could have done somewhere in the code that could cause that ?
Can you do exactly the same thing successfully from the command
line? That is, do a "move a b" with the same paths that you
are trying to use in your code?
> def makeTree(self): print 'HERE WE ARE' f = file(self.__fil ename,'r') f.close() from shutil import move from os.path import join bakname = self.__filename + '.bak' print bakname print f.closed f.close() print 'TEST',f.closed move(self.__fil ename,bakname)
Try... os.rename(self. __filename, bakname)
- Josiah
Also sprach Peter Hansen : I just do not understand what could cause this "permission s denied" for this file. Any idea of what stupid thing I could have done somewhere in the code that could cause that ?
Can you do exactly the same thing successfully from the command line? That is, do a "move a b" with the same paths that you are trying to use in your code?
A short test script is working correctly, but I will try to write something
bigger and post it here later.
Also sprach John J. Lee : (I have removed most of the logic of the code here, so I am not sure it's going to be helpful) [...]
Post a short snippet of code that runs and demonstrates the problem.
Ok, I have reduced it, but I am afraid problem comes from PyXML...
You must have some file called "test.xml "
(file is empty in my test) in the same directory as the script:
def getFileName():
from os.path import abspath,join
from sys import path
cdir = abspath(path[0])
cfile = join(cdir,'test .xml')
return cfile
from xml.sax.saxutil s import DefaultHandler
class TestReader(obje ct):
def __init__(self):
pass
def read(self,filen ame):
from _xmlplus.sax.sa x2exts import XMLValParserFac tory
parser = XMLValParserFac tory.make_parse r()
#from xml.sax.handler import feature_namespa ces,feature_val idation
#parser.setFeat ure(feature_nam espaces, 0)
dh = DefaultHandler( )
parser.setConte ntHandler(dh)
parser.setError Handler(dh)
f = file(filename,' r')
try:
parser.parse(f)
finally:
parser.close()
parser.reset()
f.close()
return 1
def ViewFile():
from xml.sax._except ions import SAXParseExcepti on
infile = getFileName()
a = TestReader()
try:
print 'A0'
pls = a.read(infile)
except SAXParseExcepti on,e:
print 'B1'
pls = {}
from shutil import move
from os import rename
bakname = infile + '.bak'
move(infile,bak name)
#rename(infile, bakname)
def main():
ViewFile()
main()
Also sprach Josiah Carlson : Try... os.rename(self. __filename, bakname)
Thanks for the idea, but unfortunately it doesnot change anything.
"Stéphane Ninin" <st*****@alussi nan.org> wrote in message
news:Xn******** *************** **********@212. 27.42.68...
.... I just do not understand what could cause this "permission s denied" for
this file. Any idea of what stupid thing I could have done somewhere in the
code that could cause that ?
.... Stephane Ninin
Hi Stéphane
Some time ago I had a "permission denied" problem on Windows that I finally
tracked down to os.system duplicating open handles at the creation instance!
The method I used to locate the problem area was by having python fire off
an instance of handle.exe (freely available from www.sysinternals.com) when
the permission error occurred to see what else had the file open.
Colin Brown
PyNZ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bmgz |
last post by:
I am have made a simple script that moves all desktop clutter (ie files that
are not *.lnk) to a specified folder
eg. c:\myhome\mydocs\desktopdebris\2003-12-16
----------------------------------------------------------------------------
-----------------
import re, os, time, shutil
os.chdir(os.environ+os.environ+"\\Desktop")
DESKTOP =
os.listdir(os.environ+os.environ+"\\Desktop")
|
by: Daniel Bickett |
last post by:
Hello,
I'm writing an application in my pastime that moves files around to
achieve various ends -- the specifics aren't particularly important.
The shutil module was chosen as the means simply because that is what
google and chm searches returned most often.
My problem has to do with shutil.move actually putting the files where
I ask it to. Citing code wouldn't serve any purpose, because I am
using the function in the most straight...
|
by: Todd7 |
last post by:
I am writing a python program to load a pdf file into an IEHtmlWindow
which displays it through adobe acrobat reader 7. Depending on the
buttons the user clicks, the program moves it to another subdirectory
with a new name. I am using python 2.4 with wxpython 2.6 on a windowsxp
machine.
I encounter a permission denied error when trying to move the file. It
appears to be caused due to the loading of the pdf file into the
IEHtmlWindow....
|
by: Antoine De Groote |
last post by:
Google tells quite some things about it, but none of them are satisfactory.
I'm on Windows, and shutil operations (e.g. move, copy) throw
Permission denied all the time, for the source files. It seems that this
is the case for all my files. But what I don't understand is that
yesterday it still worked. I didn't change anything on my system though
(at least not that I am aware of). I restarted the computer several
times to see if that...
|
by: Robert Dailey |
last post by:
Hi,
I'm trying to create a Python equivalent of the C++ "ifstream" class,
with slight behavior changes.
Basically, I want to have a "filestream" object that will allow you to
overload the '<<' and '>>' operators to stream out and stream in data,
respectively. So far this is what I have:
class filestream:
| |
by: Ahmed, Shakir |
last post by:
Is there any way to copy a file from src to dst if the dst is
exclusively open by other users.
I am using
src = 'c:\mydata\data\*.mdb'
dst = 'v:\data\all\*.mdb'
shutil.copyfile(src,dst)
|
by: Lance Hoffmeyer |
last post by:
Hey all,
As always, thanks in advance!
I am trying to save a ppt presentation but am having problems regarding spaces and am wondering
if I am doing something wrong or whether this is a bug? Also, is there a way around this other
than not using spaces in paths or filenames? I can create filesnames without spaces but don't have
much control over paths.
|
by: Roopesh |
last post by:
Hi,
I have a multithreaded application. There are two threads, T1 and T2.
Suppose that there are two folders A, B. Thread T1 fetches data from
network and creates files in folder A and after creating each file, it
moves the file to folder B, using shutil.move().
Thread T2, takes files from folder B and processes it.
Note: Only the thread T1 has access to the files in folder A.
|
by: unauthorized |
last post by:
I'm running a PHP 5.1 on an Apache 2.2 server under Windows XP which I use to develop my web apps.
Currently, I am trying to add "upload" functionality to my project, but for some reason, when the move_uploaded_file() function is called on it, the following error is generated:
Now this error may appear to be simple write permission issue, but the account that is running the service has full r/w permissions to the directory that is supposed...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |