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…
Tag: python
Upload Image using POST form data in Python-requests
I’m working with wechat APIs … here I’ve to upload an image to wechat’s server using this API http://admin.wechat.com/wiki/index.php?title=Transferring_Multimedia_Files I’m not able to post data Answer From wechat api doc: Translate the command above to python: Doc: https://docs.…
Not able to use conditional tags in for loop in Django template file
I’m using Django 1.4/python 2.7.9 (because I’m required to, I know 1.4 is pretty old now) and I’m pretty green with django/python. In my template file, I seem to be unable to use any of the cool conditional tags like ifchanged or ifequal within a for loop. For example: This throws the error …
Pipelining POST requests with python-requests
Assuming that I can verify that a bunch of POST requests are in fact logically independent, how can I set up HTTP pipelining using python-requests and force it to allow POST requests in the pipeline? Does someone have a working example? P.S. for extra points, how to handle errors for outstanding requests if p…
How can I include package_data without a MANIFEST.in file?
How can I include package_data for sdist without a MANIFEST.in file? My setup.py looks like this: Versions: I just can’t get foo/bar.txt included. Or is this blog post still true? http://blog.codekills.net/2011/07/15/lies,-more-lies-and-python-packaging-documentation-on–package_data-/ Over the las…
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…