Skip to content

Tag: python

Catch IntegrityError in Django Admin

Working with Django 1.4 I would like to catch an Integrity Error when a user does enter a duplicate value. At this moment the application just shows the default Django error page. (debug = True) model admin form At this moment I get an error page showing a ValidationError instead of an IntegrityError. (Which …

How to get the dependency tree with spaCy?

I have been trying to find how to get the dependency tree with spaCy but I can’t find anything on how to get the tree, only on how to navigate the tree. Answer It turns out, the tree is available through the tokens in a document. Would you want to find the root of the tree, you can just go

Splitting a Python list into a list of overlapping chunks

This question is similar to Slicing a list into a list of sub-lists, but in my case I want to include the last element of each previous sub-list as the first element in the next sub-list. And I have to take into account that the last sub-list always has to have at least two elements. For example: The result f…

Random 32 hexadecimal digits in Python

I am trying to find a great way to produce a 32 digit hex sequence that is random and gets its randomness from a Big Number like 10*78. For Python code I also found this: This produces a 64 digit hex string, BUT sometimes the result is 63 or even 61 characters and I’m not sure why? I need it

How to set a tkinter window to a constant size

I’m programming a little game with tkinter and briefly, I’m stuck. I have a kind od starting menu, in which are two buttons and one label. If I just create the frame everything is fine, it has the size 500×500 pixels I want the background not to change when I create the buttons and the labe, …