title: OSError: [Errno 22] Invalid argument: when trying to open a file
body: <p>im trying to open a file, but whenever I open it it returns the error <code>OSError: [Errno 22] Invalid argument:</code>. I have no idea why, I'll show you a bit of my code:</p>
  <pre><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(&quot;No files currently open&quot;)
          finishedprocess()
  
      filename = pathlib.Path(mostrecentpath).stem
      print(filename)
      fullfilename = os.path.basename(mostrecentpath)
  os.chdir(lockerdir)
          print(filename)
          with open(fullfilename, &quot;rb&quot;) as file:
              file_data = file.read()
              encrypted_data = fernet.encrypt(file_data)
              file.close()
          #writes to the binary of a file
          with open(fullfilename, &quot;wb&quot;) as file:
              file.write(encrypted_data)
              file.close()
          os.chdir(initialdir)
  </code></pre>
  <p>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, <code>test</code>, however in my full error I get the error <code>OSError: [Errno 22] Invalid argument: 'test.txt\n'</code>. Any ideas?</p>