From df53ebf85b7e1733eb291b9785efa80bd16f9577 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Tue, 4 Apr 2023 18:13:13 +0200 Subject: [PATCH] 'Bringing back python files;' --- python/.project | 17 +++++++++++++++++ python/.pydevproject | 8 ++++++++ python/net/__init__.py | 0 python/net/hypki/Area.py | 18 ++++++++++++++++++ python/net/hypki/Figure.py | 27 +++++++++++++++++++++++++++ python/net/hypki/Main.py | 33 +++++++++++++++++++++++++++++++++ python/net/hypki/Square.py | 24 ++++++++++++++++++++++++ python/net/hypki/__init__.py | 0 8 files changed, 127 insertions(+) create mode 100644 python/.project create mode 100644 python/.pydevproject create mode 100644 python/net/__init__.py create mode 100644 python/net/hypki/Area.py create mode 100644 python/net/hypki/Figure.py create mode 100644 python/net/hypki/Main.py create mode 100644 python/net/hypki/Square.py create mode 100644 python/net/hypki/__init__.py diff --git a/python/.project b/python/.project new file mode 100644 index 0000000..498050e --- /dev/null +++ b/python/.project @@ -0,0 +1,17 @@ + + + wmii-prog-obiektowe-python + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/python/.pydevproject b/python/.pydevproject new file mode 100644 index 0000000..c3434da --- /dev/null +++ b/python/.pydevproject @@ -0,0 +1,8 @@ + + + +/${PROJECT_DIR_NAME} + +python 3.0 +Default + diff --git a/python/net/__init__.py b/python/net/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python/net/hypki/Area.py b/python/net/hypki/Area.py new file mode 100644 index 0000000..3b2b82c --- /dev/null +++ b/python/net/hypki/Area.py @@ -0,0 +1,18 @@ +''' +Created on Apr 4, 2023 + +@author: ahypki +''' + +class Area(): + ''' + classdocs + ''' + + def __init__(self): + ''' + Constructor + ''' + + def compute_area(self): + pass \ No newline at end of file diff --git a/python/net/hypki/Figure.py b/python/net/hypki/Figure.py new file mode 100644 index 0000000..7be47bc --- /dev/null +++ b/python/net/hypki/Figure.py @@ -0,0 +1,27 @@ +''' +Created on Apr 4, 2023 + +@author: ahypki +''' + +class Figure(): + ''' + classdocs + ''' + + __name = ''; + + def __init__(self, newName = 'Default __name'): + ''' + Constructor + ''' + self.__name = newName; + + def get_name(self): + return self.__name + + def set_name(self, value): + self.__name = value + + def __str__(self): + return "Figure with name= {0}".format(self.__name) diff --git a/python/net/hypki/Main.py b/python/net/hypki/Main.py new file mode 100644 index 0000000..dc4b545 --- /dev/null +++ b/python/net/hypki/Main.py @@ -0,0 +1,33 @@ +''' +Created on Apr 4, 2023 + +@author: ahypki +''' +from net.hypki.Figure import Figure +from net.hypki.Square import Square + +if __name__ == '__main__': + f = Figure() + f.__name = "New name" + + f2 = Figure('Another name') + + print(str(f)) + print(str(f2)) + + s1 = Square('Square1') + print(str(s1)) +# print(str(s1.__name)) # will not work + print(s1.get_name()) + + # generics... actually are not needed - duck typing + figList = [Figure('f1'), Figure('f2')] + print(figList) + print(*figList) # uses our __str__ function + + figList = [Square('s1'), Square('s2')] + print(figList) + print(*figList) # uses our __str__ function + print(figList[0].get_name()) # but there is no help from IDE + + print('Finished!') \ No newline at end of file diff --git a/python/net/hypki/Square.py b/python/net/hypki/Square.py new file mode 100644 index 0000000..61c63b0 --- /dev/null +++ b/python/net/hypki/Square.py @@ -0,0 +1,24 @@ +''' +Created on Apr 4, 2023 + +@author: ahypki +''' +from net.hypki.Figure import Figure +from net.hypki.Area import Area + +class Square(Figure, Area): + ''' + classdocs + ''' + + def __init__(self, newName): + ''' + Constructor + ''' + super().__init__(newName) + + def __str__(self): + return "Square with name= {0} has area= {1}".format(self.get_name(), self.compute_area()) + + def compute_area(self): + return 4.0 \ No newline at end of file diff --git a/python/net/hypki/__init__.py b/python/net/hypki/__init__.py new file mode 100644 index 0000000..e69de29