Skip to content

Tag: python

Text difference algorithm

I need an algorithm that can compare two text files and highlight their difference and ( even better!) can compute their difference in a meaningful way (like two similar files should have a similarity score higher than two dissimilar files, with the word “similar” defined in the normal terms). It …

Is there an easy way to populate SlugField from CharField?

Is there a built-in way to get the slug field to autopopulate based on the title? Perhaps in the Admin and outside of the Admin. Answer for Admin in Django 1.0 and up, you’d need to use in your admin.py Your key in the prepopulated_fields dictionary is the field you want filled, and the value is a tuple…

How to read the RGB value of a given pixel in Python?

If I open an image with open(“image.jpg”), how can I get the RGB values of a pixel assuming I have the coordinates of the pixel? Then, how can I do the reverse of this? Starting with a blank graphic, ‘write’ a pixel with a certain RGB value? I would prefer if I didn’t have to dow…

Python Date Comparisons

I would like to find out if a particular python datetime object is older than X hours or minutes. I am trying to do something similar to: This generates a type error. What is the proper way to do date time comparison in python? I already looked at WorkingWithTime which is close but not exactly what I want. I …