Python Forum
code with exception arguments doen't work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code with exception arguments doen't work
#1
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();
Reply
#2
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hi need help to make this code work correctly atulkul1985 5 702 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 626 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 870 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Beginner: Code not work when longer list raiviscoding 2 765 May-19-2023, 11:19 AM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,681 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 1,383 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 842 Dec-29-2022, 08:59 PM
Last Post: deanhystad
Question log.exception() without arguments in old Python versions? cthart 5 1,117 Nov-19-2022, 07:09 PM
Last Post: Gribouillis
  Something the code dont work AlexPython 13 2,128 Oct-17-2022, 08:34 PM
Last Post: AlexPython
  cannot get code to work Led_Zeppelin 10 2,311 Jun-30-2022, 06:28 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020