diff options
Diffstat (limited to 'pycrctrl.py')
| -rw-r--r-- | pycrctrl.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/pycrctrl.py b/pycrctrl.py index 6935512..c54d147 100644 --- a/pycrctrl.py +++ b/pycrctrl.py @@ -74,13 +74,27 @@ class QList(QObject): if type(name) != int: raise ValueError("Wrong datatype for name!") else: - return self.list[name] + try: + return self.list[name] + except IndexError as e: + raise IndexError(e.args[0]) from None def __lshift__(self, other): if self.typeclass and not isinstance(other, self.typeclass): raise ValueError("Wrong datatype") else: self.list.append(other) + return self + + def __rshift__(self, other): + if isinstance(other, list) or isinstance(other, QList): + item = self.list[-1] + try: + other.append(item) + self.list.pop() + except Exception: + raise TypeError("Cannot pass item to {}!".format(other)) from None + def __call__(self): return self.list @@ -89,13 +103,16 @@ class QList(QObject): return len(self.list) def __repr__(self): - return "{}({})".format(self.__name__, self.list) + return "{}({})".format(self.__class__.__name__, self.list) # Methods def isEmpty(self): return len(self.list) == 0 + def append(self, item): + return self.__lshift__(item) + class QStringList(QList): typeclass = str |
