Answer the question
In order to leave comments, you need to log in
Why does the code behave like this?
Good afternoon, the problem is this.
Import module os. I create a class, with a class constructor, it has the following.
class SG():
def __init__(self):
self.local_drive = os.environ['systemdrive']
os.chdir('C:/Dir1')
, copy the files into it through shutil.copy
, and then, let's say, I need to delete this folder. If you do this right away, it gives an error, it's understandable, we kind of keep the folder open. I am executing the code os.chdir(self.local_drive)
. I try to delete the folder again, again the same error, if you look at the path with os.getcwd()
, it shows C:/Dir1. However, if you go not to the root of the disk, but, say, to a folder with Windows (I'm on Windows), then everything is deleted normally. Why is this happening?
Answer the question
In order to leave comments, you need to log in
And because Windows! It does not change the directory if only a drive selection occurs.
Call cmd and do the following:
Microsoft Windows [Version 6.1.7601]
(c) Корпорация Майкрософт (Microsoft Corp.), 2009. Все права защищены.
C:\Users\leah>cd C:
C:\Users\leah
C:\Users\leah>cd C:\
C:\>
os.chdir(self.local_drive+os.sep)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question