teil8.
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
from partner.Anschrift import Anschrift
|
||||
|
||||
class Person:
|
||||
# Konstruktor
|
||||
def __init__(self,vorname, name):
|
||||
def __init__(self,vorname, name,anschrift):
|
||||
self.vorname = vorname
|
||||
self.name = name
|
||||
|
||||
print(type(Anschrift))
|
||||
if anschrift == None:
|
||||
raise TypeError('anschrift darf nicht None sein')
|
||||
|
||||
if not isinstance(anschrift, Anschrift):
|
||||
raise TypeError('anschrift ist vom falschen Typ')
|
||||
|
||||
self.anschrift = anschrift
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from . import Telefonnummer
|
||||
from . import Person
|
||||
from . import Anschrift
|
||||
|
||||
__all__ = ['telefonnnummer','person','anschrift']
|
||||
|
||||
|
@@ -1,9 +0,0 @@
|
||||
class Anschrift:
|
||||
def __init__(self, strasse, hausnummer, plz, ort):
|
||||
self.strasse = strasse
|
||||
self.hausnummer = hausnummer
|
||||
self.plz = plz
|
||||
self.ort = ort
|
||||
|
||||
def __str__(self):
|
||||
return self.strasse + ' ' + self.hausnummer + '\n' + self.plz + ' ' + self.ort
|
@@ -1,7 +1,9 @@
|
||||
from partner.Telefonnummer import Telefonnummer
|
||||
from partner.Person import Person
|
||||
from partner.Anschrift import Anschrift
|
||||
|
||||
p= Person('Homer','Simpson')
|
||||
anschrift = Anschrift('Evergreen Terrace', '742','55555', 'Springfield')
|
||||
p= Person('Homer','Simpson', [0,1])
|
||||
tel = Telefonnummer('44','221','12345678')
|
||||
|
||||
print(str(tel))
|
||||
|
17
teil8/exception.py
Normal file
17
teil8/exception.py
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
def func(wert):
|
||||
|
||||
if not isinstance(wert,int):
|
||||
raise TypeError('weertr muss ein int sein.')
|
||||
|
||||
if wert >0:
|
||||
print('Wert ist in Ordnung')
|
||||
else:
|
||||
raise ValueError('wert muss größer 0 sein')
|
||||
|
||||
|
||||
|
||||
func(7)
|
||||
func(-1)
|
||||
|
27
teil8/finally.py
Normal file
27
teil8/finally.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# encode utf-8
|
||||
|
||||
def func(wert):
|
||||
|
||||
if not isinstance(wert,int):
|
||||
raise TypeError('weertr muss ein int sein.')
|
||||
|
||||
if wert >0:
|
||||
print('Wert ist in Ordnung')
|
||||
else:
|
||||
raise ValueError('wert muss größer 0 sein')
|
||||
|
||||
|
||||
|
||||
func(7)
|
||||
|
||||
try:
|
||||
func(-1)
|
||||
except ValueError:
|
||||
print('Da haben wir doch einen falschen Wert übergeben.')
|
||||
finally:
|
||||
# Dieser Block wird immer ausgeführt, egal ob mit oder ohne Exception
|
||||
# Hier kannst z.B. Datenbankverbindungen schliessen, Speicher freigeben oder temporäre Dateien löschen
|
||||
pass
|
||||
|
||||
|
||||
|
7
teil8/meineexception.py
Normal file
7
teil8/meineexception.py
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
class MeineException(Exception):
|
||||
pass
|
||||
# def __init__(message):
|
||||
# super().__init__(message)
|
||||
|
||||
|
9
teil8/myexception.py
Normal file
9
teil8/myexception.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from meineexception import MeineException
|
||||
|
||||
def func():
|
||||
raise MeineException('meine eigene Exception')
|
||||
|
||||
|
||||
|
||||
func()
|
||||
|
21
teil8/try.py
Normal file
21
teil8/try.py
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
def func(wert):
|
||||
|
||||
if not isinstance(wert,int):
|
||||
raise TypeError('weertr muss ein int sein.')
|
||||
|
||||
if wert >0:
|
||||
print('Wert ist in Ordnung')
|
||||
else:
|
||||
raise ValueError('wert muss größer 0 sein')
|
||||
|
||||
|
||||
|
||||
func(7)
|
||||
|
||||
try:
|
||||
func(-1)
|
||||
except ValueError:
|
||||
print('Da haben wir doch einen falschen Wert übergeben.')
|
||||
|
||||
|
Reference in New Issue
Block a user