Skip to content
Advertisement

Tag: loops

Define Python type hints in for-loop inside class body

I have the following code in Python: The type hints are used upon instantiation of MyDesign to dynamically add instances of the various Modules. I chose this syntax because the class MyDesign is really just a “template” defining what Modules it’s composed of, but the instantiation of modules needs some arguments only available when MyDesign is being instantiated. I would

Replace All Specific Characters in String using Python

I have a problem with a function I am trying to implement that needs to replace some letters (in a given string), for some other characters, defined on a dictionary. I have this dictionary: I want to pass a string that when a character matches any key from the dictionary (case insensitive match), it tries to save all the possible

How to iterate through neighbours in 2D coordinates?

In a 2D plane, I want to check the neighbouring points until meeting a condition. For example, take a red pixel in this image (x,y). I want to iterate to find the white pixel closest to the selected red pixel. This is an updated image provided by @Pranav Hosangadi My original code is now irrelevant. A possible solution is to

Start and stop command to break a loop

I’m working on a webscraping code, and the process is quite long. Thus, I would like to start and stop it in a fancy way, with a button using tkinter. But I couldn’t find any solution on the web. The .after() function doesn’t seems to be a good option as I don’t want to restart my loop each time. My

I want to extract all the values that a class object holds

I have an object Vm of Type <class ‘azure.mgmt.compute.v2019_07_01.models._models_py3.VirtualMachine’> I want to iterate over this object by a loop so that I don’t have to manually extract the values. Yes I’ve tried isinstance to check whether the value is of type <class ‘azure.mgmt.compute.v2019_07_01.models._models_py3.VirtualMachine’> and extract but in the next iteration it fails. For example let’s consider vm to be an

Advertisement