Skip to content

Tag: python

Access-Control-Allow-Origin in Django app

I’m developing a Phonegap app for my Django based app, but when trying to make Ajax calls I get this error: How can I make it so my Django app allows cross origin for some urls? Here’s my Ajax code: Answer Django by default does not provide the headers necessary to provide cross origin. The easies…

Socket Programming with Python server and Android client

I want to setup a socket interface. PC side runs a very simple socket server written in Python to test the connection: An Android client application will connect to PC: However, I cannot establish a connection between PC and Android device. Any idea to fix this? Answer As you haven’t detailed if you&#82…

Get all keys in Redis database with python

There is a post about a Redis command to get all available keys, but I would like to do it with Python. Any way to do this? Answer Use scan_iter() scan_iter() is superior to keys() for large numbers of keys because it gives you an iterator you can use rather than trying to load all the keys into memory. I

Python: datetime64 issues with range

I am trying to have a vector of seconds between two time intervals: For some reason when I print range I get: So the length is 23401 which is what I want but definitely not the correct time interval. Why is that? Also, if I have a DataFrame df with a column of datetime64 format that looks like: Once I

Choose at random from combinations

I can make a list of all combinations using list(itertools.combinations(range(n), m)) but this will typically be very large. Given n and m, how can I choose a combination uniformly at random without first constructing a massive list?? Answer From http://docs.python.org/2/library/itertools.html#recipes

How can I subclass a Pandas DataFrame?

Subclassing Pandas classes seems a common need, but I could not find references on the subject. (It seems that Pandas developers are still working on it: Easier subclassing #60.) There are some SO questions on the subject, but I am hoping that someone here can provide a more systematic account on the current …