python-3.8

Logging every exception within custom Python package

Logging every exception within custom Python package Question: I’m working on implementing logging into a custom Python package. Throughout the package, exceptions can be raised if inputs are unacceptable, or if tests fail, etc. I’d like to log any exceptions that are raised within the package using the built-in logging module. So far, I’ve seen …

Total answers: 1

To find max continuous subarray sum of size M

To find max continuous subarray sum of size M Question: I am new to the competitive programming. I am finding trouble in doing the following problem. The question is that you have given an array or list. And a number M, now you hav to find the continuous subarray of size M having the largest …

Total answers: 5

AttributeError: 'NoneType' object has no attribute 'remove' issue

AttributeError: 'NoneType' object has no attribute 'remove' issue Question: I want to remove certain values from a list if they are elements in a specified other list, as below. Ideally this would return list2 = ["e","f","g"], but instead it returns the above error as it seems once one of the elements is removed list1 becomes …

Total answers: 1

Python str formatting

Python str formatting Question: I am using Python 3.8.10. result = "<svg id='{id}’ class='{class}’ height='{height}{unit}’ width='{width}{unit}’>".format(id=image_id, class=html_class, height=str(height), unit=unit_of_measure) I get this error message: File "/home/michael/PycharmProjects/images_outer/images_project/images/templatetags/images.py", line 131 result = "<svg id='{id}’ class='{class}’ height='{height}{unit}’ width='{width}{unit}’>".format(id=image_id, class=html_class, height=str(height), unit=str(unit_of_measure)) ^ SyntaxError: invalid syntax python-BaseException Process finished with exit code 130 (interrupted by signal 2: SIGINT) What …

Total answers: 2

How to run sklearn library with native tensorflow on m1 mac

How to run sklearn library with native tensorflow on m1 mac Question: I have installed TensorFlow using a virtual environment running python 3.8 as described by Apple. This should theoretically run natively and utilise the GPU. I tried installing TensorFlow using miniforge last time and it was not able to use the GPU as miniforge …

Total answers: 1

Common substring in list of strings

Common substring in list of strings Question: i encountered a problem while trying to solve a problem where given some strings and their lengths, you need to find their common substring. My code for the part where it loops through the list and then each through each word in it is this: num_of_cases = int(input()) …

Total answers: 3

How to call Python function by name dynamically using a string?

How to call Python function by name dynamically using a string? Question: I have a Python function call like so: import torchvision model = torchvision.models.resnet18(pretrained=configs.use_trained_models) Which works fine. If I attempt to make it dynamic: import torchvision model_name = ‘resnet18’ model = torchvision.models[model_name](pretrained=configs.use_trained_models) then it fails with: TypeError: ‘module’ object is not subscriptable Which makes …

Total answers: 2

Showing the setup screen only on first launch in kivy

Showing the setup screen only on first launch in kivy Question: I am trying to make an app with kivy and kivymd but I can’t figure out how I can make the setup screen show up only the first time. This is how the application is going to work: User launches the application after installation …

Total answers: 2

How to delete character or line from terminal in Python?

How to delete character or line from terminal in Python? Question: I want to erase character or line from terminal in Python. For example, I printed "Hello World" using print("Hello World"). And then I used time.sleep(3) to wait 3 seconds. Then I want to delete one character in terminal, so terminal will be Hello Worl. …

Total answers: 4