(c) 2023 Technische Hochschule Augsburg - Fakultät für Informatik - Prof.Dr.Nik Klever - Impressum
%%writefile m1.py
print("im Modul m1.py: __file__: {}".format(__file__))
class c1():
def __init__(self):
print("in der Klasse c1 des Moduls m1.py")
def f1(self):
print("Name der Klasse: {}".format(self.__class__))
print("Name des Moduls: {}".format(self.__module__))
def f2(self):
print("Name der Funktion f2: {}".format(self.f2.__name__))
Writing m1.py
!python m1.py
im Modul m1.py: __file__: m1.py
import m1
im Modul m1.py: __file__: /home/student/SE2016FS02/Videos/Module/m1.py
type(m1)
module
print(m1.__file__)
/home/student/SE2016FS02/Videos/Module/m1.py
i1 = m1.c1()
in der Klasse c1 des Moduls m1.py
type(i1)
m1.c1
i1.f1()
Name der Klasse: <class 'm1.c1'> Name des Moduls: m1
i1.f2()
Name der Funktion f2: f2
%%writefile testmodul.py
print("- Wir sind jetzt in testmodul.py")
print("- testmodul.py: __file__: {}".format(__file__))
print("- testmodul.py: __name__: {}".format(__name__))
if __name__ == "__main__":
print("- jetzt habe ich testmodul.py direkt aufgerufen")
else:
print("- Wir verlassen jetzt testmodul.py")
Writing testmodul.py
!python testmodul.py
- Wir sind jetzt in testmodul.py - testmodul.py: __file__: testmodul.py - testmodul.py: __name__: __main__ - jetzt habe ich testmodul.py direkt aufgerufen
%%writefile testvontestmodul.py
print("Wir sind jetzt in testvontestmodul.py")
import testmodul
print("Nach dem import von testmodul")
print("testvontestmodul.py: __file__: {}".format(__file__))
print("testvontestmodul.py: __name__: {}".format(__name__))
Writing testvontestmodul.py
!python testvontestmodul.py
Wir sind jetzt in testvontestmodul.py - Wir sind jetzt in testmodul.py - testmodul.py: __file__: /home/student/SE2016FS02/Videos/Module/testmodul.py - testmodul.py: __name__: testmodul - Wir verlassen jetzt testmodul.py Nach dem import von testmodul testvontestmodul.py: __file__: testvontestmodul.py testvontestmodul.py: __name__: __main__
%%writefile rechne.py
def addiere(parameter1, parameter2):
return parameter1+parameter2
def multipliziere(parameter1,parameter2):
return parameter1*parameter2
if __name__ == "__main__":
print("test addiere: {}+{}={}".format(2,6,addiere(2,6)))
print("test multipliziere: {}*{}={}".format(4,5,multipliziere(4,5)))
Writing rechne.py
!python rechne.py
test addiere: 2+6=8 test multipliziere: 4*5=20
%%writefile verwende_rechne.py
import rechne
print("Addition: {}+{}={}".format(3,7,rechne.addiere(3,7)))
print("Multiplikation: {}*{}={}".format(6,8,rechne.multipliziere(6,8)))
Writing verwende_rechne.py
!python verwende_rechne.py
Addition: 3+7=10 Multiplikation: 6*8=48