Skip to content

Tag: python

Python comma and divide an integer

Example output is: 8993 / 18782 I see some questions like that, but all of them was about “float”. I want to make these integers like that: 8,9K / 18,7K What is the “proper” way to do that? Answer Try this function: And replace your final line of code with the function: Also, if you do…

Dendrogram through scipy given a similarity matrix

I have computed a jaccard similarity matrix with Python. I want to cluster highest similarities to lowest, however, no matter what linkage function I use it produces the same dendrogram! I have a feeling that the function assumes that my matrix is of original data, but I have already computed the first simila…

Generate random colors (RGB)

I just picked up image processing in python this past week at the suggestion of a friend to generate patterns of random colors. I found this piece of script online that generates a wide array of different colors across the RGB spectrum. I am simply interesting in appending this script to only generate one of …

Ansible write variables into YAML file

I have a specific ansible variable structure that I want to get from the vault into a yaml file on my hosts. Lets assume a structure like this: I need something like a “generic” template to output whatever “secrets” contains at the moment, since the content changes almost completely ba…

Python smtp.connect does not connect

I’m writing a small python script to send an email, but my code isn’t even getting past smtp connection. I’m using the following code, but I never see “Connected”. Additionally, I’m not seeing an exception thrown, so I think it’s hanging on something. Answer Port 465 …

pytest.mark.parameterize not “finding” fixtures

I’m writing tests for a small library and I decided to use py.test after hearing so many good things about it. However, pytest.mark.parameterize is giving me some issues. At first, I thought maybe I just mismatched some parens and it went off looking for a fixture elsewhere. So I decided to start with t…