import os
dir_name = "new_dir"
os.mkdir(dir_name)
os.chdir(dir_name)
print("THE cwd now is in " + os.getcwd())
os.rmdir("../"+dir_name)
print(dir_name+" deleted")
print("Checking CWD")
print("THE script now is in " + os.getcwd())
the getcwd returns error instead of checking the current working directory can someone point me to the reason for that as documentation or just tell me why
You were in a particular directory, then deleted it out from under yourself, leaving yourself with a "working directory" that doesn't exist. Don't do that. Leave the directory before deleting it, or weird stuff will happen in cases like this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.