Skip to content

Tag: python

can’t see records inserted by django test case

I’m trying to provide integration to my django application from subversion through the post commit hook. I have a django test case (a subclass of unittest.TestCase) that (a) inserts a couple of records into a table, (b) spawns an svn commit, (c) svn commit runs a hook that uses my django model to look u…

How to find the longest word with python?

How can I use python to find the longest word from a set of words? I can find the first word like this: Answer If I understand your question correctly: split() splits the string into words (seperated by whitespace); max() finds the largest element using the builtin len() function, i.e. the string length, as t…

What is the best way to call a script from another script? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 10 months ago. The community reviewed whether to reopen this question 10 months ago and left it closed: …

Controlling mouse with Python

How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows? Answer Tested on WinXP, Python 2.6 (3.x also tested) after installing pywin32 (pywin32-214.win32-py2.6.exe in my case):

How to efficiently calculate a running standard deviation

I have an array of lists of numbers, e.g.: I would like to efficiently calculate the mean and standard deviation at each index of a list, across all array elements. To do the mean, I have been looping through the array and summing the value at a given index of a list. At the end, I divide each value in

Print current call stack from a method in code

In Python, how can I print the current call stack from within a method (for debugging purposes). Answer Here’s an example of getting the stack via the traceback module, and printing it: If you really only want to print the stack to stderr, you can use: Or to print to stdout (useful if want to keep redir…

Equivalent of NotImplementedError for fields in Python

In Python 2.x when you want to mark a method as abstract, you can define it like so: Then if you forget to override it, you get a nice reminder exception. Is there an equivalent way to mark a field as abstract? Or is stating it in the class docstring all you can do? At first I thought I could

How to sort objects by multiple keys?

Or, practically, how can I sort a list of dictionaries by multiple keys? I have a list of dicts: and I need to use a multi key sort reversed by Total_Points, then not reversed by TOT_PTS_Misc. This can be done at the command prompt like so: But I have to run this through a function, where I pass in the