Python Forum

Full Version: code with exception arguments doen't work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am trying to write code with exception arguments. Somehow it doesn't work.
What am i doing wrong? Any input is much appreciated!

import sys

try:
    File = open('myfile.txt')
except IOError as e:
    print("Bestand wordt niet geopend!\r\n" +
          "Foutnummer: (0)\r\n".format(e.erno) +
          "Fouttekst: (0)".format(e.strerror))
else:
    print("Bestand probleemloos geopend.")
    File.close();
MarteenRo Wrote:Somehow it doesn't work.
What do you mean by that? "it doesn't work" is not a very useful error report. Can you describe a situation where the program doesn't behave as expected?