Python Try:Except ( Hata Yakalama ) Sorun
-
Arkadaşlaar kodu böyle yapıyorum fakat bu işlem bir işe yaramıyor.Kodları atıyorum yinede IOError veya Attirbute error veriyor.
from Tkinter import * import os from tkFileDialog import * try: def kaydet(): global Kayitet Kayitet = asksaveasfile(mode="w") yazi = yazialani.get(0.0,END) Kayitet.write(yazi) Kayitet.close() def yenidosya(): yazialani.delete("1.0", END) def dosyaac(): ac = askopenfilename() acilanyazi = open(ac,"r") for y in acilanyazi: yazialani.insert(INSERT,y) anapencere = Tk() anapencere.wm_title("PyPad Alfa Non-Stable Version") ustmenu = Menu() ustmenu.add_command(label="Yeni",command=yenidosya) ustmenu.add_command(label="Kaydet",command=kaydet) ustmenu.add_command(label="Dosya Aç",command=dosyaac) anapencere.config(menu=ustmenu) #TextArea yazialani = Text() yazialani.pack() mainloop() except (IOError,AttributeError): pass -
except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) except AttributeError as e: print "Attribute error({0}): {1}".format(e.errno, e.strerror) except: print "Unexpected error:", sys.exc_info()[0] raise
SpArK tarafından 14/Oca/14 20:14 tarihinde düzenlenmiştir
boyle ayirip denesene bi -
SpArK bunu yazdı
except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) except AttributeError as e: print "Attribute error({0}): {1}".format(e.errno, e.strerror) except: print "Unexpected error:", sys.exc_info()[0] raise
boyle ayirip denesene bi
Değişen birşey yok hocam aynı sorun
-
25. satırdaki
acilanyazi=open(ac,"r") yerine aşağıdakini koy hocam.try:
acilanyazi=open(ac,"r")
except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) except AttributeError as e: print "Attribute error({0}): {1}".format(e.errno, e.strerror) except: print "Unexpected error:", sys.exc_info()[0] -
Buremba bunu yazdı
25. satırdaki
acilanyazi=open(ac,"r") yerine aşağıdakini koy hocam.try:
acilanyazi=open(ac,"r")
except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) except AttributeError as e: print "Attribute error({0}): {1}".format(e.errno, e.strerror) except: print "Unexpected error:", sys.exc_info()[0]Eyvallah hocam bak şimdi anladım mantığını :)
Toplam Hit: 1158 Toplam Mesaj: 5
