Tags:

Elegantly changing the color of a plot frame in matplotlib


This is a kind of follow-up question to this post, where the coloring of axes, ticks and labels was discussed. I hope it is alright to open a new, extended question for this. Changing the color of a …

Calculating arithmetic mean (one type of average) in Python

Tags: , , , ,


Is there a built-in or standard library method in Python to calculate the arithmetic mean (one type of average) of a list of numbers?

Tags:

Is there a way to create multiline comments in Python?


I have recently started studying Python, but I couldn’t find how to implement multi-line comments. Most languages have block comment symbols like /* */ I tried this in Python, but it throws an …

sqlite3.OperationalError: unable to open database file

Tags: , , , ,


I get this error when setting up a server in Django. It is sqlite3 which means it should create the .db file but it doesn’t seem to be doing so. I’ve stipulated SQLite as the backend and an absolute …

A python web framework for google app engine

Tags: , , , ,


(Please note that this question and some of the answers are old) I want to use an existing python framework to develop an application on google appengine. It should be quick and easy to start and …

Tags: file-io python

How to to read a matrix from a given file?

Tags: ,


I have a text file which contains matrix of N * M dimensions. For example the input.txt file contains the following: 0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0 0,…

How to calculate the angle between a line and the horizontal axis?

Tags: , ,


In a programming language (Python, C#, etc) I need to determine how to calculate the angle between a line and the horizontal axis? I think an image describes best what I want: Given (P1x,P1y) and (P2x,P2y) what is the best way to calculate this angle? The origin is in the topleft and only the positive quadrant is used. Answer First find the difference between the start point and the end point (here, this is more of a directed line segment, not a “line”, since lines extend infinitely and don’t start at a particular point). Then calculate the angle (which runs

Tags:

Best way to convert string to bytes in Python 3?


There appear to be two different ways to convert a string to bytes, as seen in the answers to TypeError: ‘str’ does not support the buffer interface Which of these methods would be better or …

Tags:

Fastest way to check if a value exists in a list


What is the fastest way to know if a value exists in a list (a list with millions of values in it) and what its index is? I know that all values in the list are unique as in this example. The first …

Tags:

Django – how to create a file and save it to a model’s FileField?


Here’s my model. What I want to do is generate a new file and overwrite the existing one whenever a model instance is saved: class Kitten(models.Model): claw_size = … license_file = models….