'OSError: [Errno 22] Invalid argument: when trying to open a file
im trying to open a file, but whenever I open it it returns the error OSError: [Errno 22] Invalid argument:. I have no idea why, I'll show you a bit of my code:
initialdir = pathlib.Path(__file__).parent.absolute()
lockerdir = (str(initialdir) + str('/locker'))
try:
file = open('openfile.ivd', 'r+')
mostrecentpath = file.read()
file.close()
except:
print("No files currently open")
finishedprocess()
filename = pathlib.Path(mostrecentpath).stem
print(filename)
fullfilename = os.path.basename(mostrecentpath)
os.chdir(lockerdir)
print(filename)
with open(fullfilename, "rb") as file:
file_data = file.read()
encrypted_data = fernet.encrypt(file_data)
file.close()
#writes to the binary of a file
with open(fullfilename, "wb") as file:
file.write(encrypted_data)
file.close()
os.chdir(initialdir)
openfile.ivd already exists. It contains the path of the last file taht was opened by my program. When printing filename I get the output, test, however in my full error I get the error OSError: [Errno 22] Invalid argument: 'test.txt\n'. Any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
