0

I tried to write in a file using the open() function with the mode wb this mode opens a file for writing, creates the file if it does not exist in a binary mode. When the following code is execute it throws a FileNotFound exception Any thought what it could be ? This is the code:

dir = ""
idFile = "001"
with open("{0}tmp/file_{1}".format(dir, idFile), "wb") as file:
    file.write("hello")

This is the error i got after executed the code before.

enter image description here

Danny
  • 47
  • 11
  • Does the *directory* exist? Remember, you're telling it `tmp/`, not `/tmp`, so it's looking for a `tmp` directory *relative to the current working directory your code is running in*. – Charles Duffy Feb 03 '20 at 16:15
  • `open()` will create a _file_, but not a _subdirectory_. – John Gordon Feb 03 '20 at 16:16
  • BTW, always paste errors as text, not screenshots. Screenshots can't be indexed for search, take more bandwidth to transfer, display poorly on higher-DPI displays, can't be copied-and-pasted, don't work well with accessibility tools like screen readers and high-contrast fonts, etc. – Charles Duffy Feb 03 '20 at 16:16

0 Answers0