Python – Line too long, how can I break this?

I have this line of code: self.order_total = self.lineitems.aggregate(Sum(‘lineitem_total’))[‘lineitem_total__sum’] or 0 It is too long for pep8 validation. I had a look at the docs (https://peps.python.org/pep-0008/#maximum-line-length) but i can’t figure out how best to break it. Can someone advise me please? thanks >Solution : As I understand you mean Line Breaking. It is too easy… Read More Python – Line too long, how can I break this?

Python Class – Can't find out how to use method return value within another method

So this is the class i’m testing: class Test: def find_string(self, string): self.string = string return string.find(string) def add_string(self, string): found = self.find_string(‘bar’) if found == -1: string = string + ‘ bar’ return string Here is my setup: test_string = ‘foo’ Test1 = Test() new_string = Test1.add_string(string) Results Expected result: foo bar Result: foo… Read More Python Class – Can't find out how to use method return value within another method

when using python logging.Formatter() can I use a pep8 style or does it have to be on one line

I’m learning how to use the python logging module and wanted to know if it’s possible to split the code below so the variables are easily readable and identified: formatter_f = logging.Formatter(‘%(asctime)s,%(levelname)s,%(module)s,%(funcName)s,%(message)s’,datefmt=’%m/%d/%Y %H:%M:%S’) which results in: 03/25/2022 09:51:28,WARNING,main,<module>,first 03/25/2022 09:51:28,ERROR,sub2,div,error happened: division by zero 03/25/2022 09:51:28,WARNING,main,<module>,done I tried to do a more pep8 style with… Read More when using python logging.Formatter() can I use a pep8 style or does it have to be on one line

How to create custom input types for function defenition for external libraries in Python?

I wanted to write functions with detailed types so that during usage of any typecheker e.g. Pylance in VScode you could clearly see the input type. I managed to achieve some result with default input types like int and then extended it to numpy.ndarray. But this is where I ran into an issue. The code… Read More How to create custom input types for function defenition for external libraries in Python?