python

python: image to 2-dimensional list

Hi, everyone Was just curious if there is a python lib that could make a 2-dimensional list of (R,G,B) data out of an image file. Thanks in advance ...

Logging users out of a Django site after N minutes of inactivity

I'm working on a website that requires us to log a user out after N minutes of inactivity. Are there any best practices for this using Django? ...

Python if statement efficiency

A friend (fellow low skill level recreational python scripter) asked me to look over some code. I noticed that he had 7 separate statements that basically said. if ( a and b and c): do something the statements a,b,c all tested their equality or lack of to set values. As I looked at it I found that because of the nature of the test...

Lightweight Object->Database in python

I am in need of a lightweight way to store dictionaries of data into a database. What I need is something that: Creates a database table from a simple type description (int, float, datetime etc) Takes a dictionary object and inserts it into the database (including handling datetime objects!) If possible: Can handle basic references, s...

How do I set a matplotlib colorbar extents?

I'd like to display a colorbar representing an image's raw values along side a matplotlib imshow subplot which displays that image, normalized. I've been able to draw the image and a colorbar successfully like this, but the colorbar min and max values represent the normalized (0,1) image instead of the raw (0,99) image. f = plt.figure(...

HOW TO: Draggable legend in matplotlib

QUESTION: I'm drawing a legend on an axes object in matplotlib but the default positioning which claims to place it in a smart place doesn't seem to work. Ideally, I'd like to have the legend be draggable by the user. How can this be done? SOLUTION: Well, I found bits and pieces of the solution scattered among mailing lists. I've come...

Python mechanize to follow image links?

mechanize's Browser class is great and it's follow_link() function is great too. But what to do with this kind of links: <a href="http://example.com"&gt;&lt;img src="…"></a> Is there any way to follow such links? The text attribute of this type of links is simply '[IMG]', so AFAIK, there is no way to differentiate such links. Any help...

Pyglet isn't displaying fonts to the correct size.

I took advice from an answer to another question I asked which led to me using a DPI of 72 to match points to pixels for the text in my game. The problem is that pyglet is rendering text far too big or far too small. Perhaps it depends on the framebuffer size? I haven't got a clue. Here's my code for rendering fonts: class Font(): ...

Simple non-network concurrency with Twisted

Dear pythoners, I have a problem with using Twisted for simple concurrency in python. The problem is - I don't know how to do it and all online resources are about Twisted networking abilities. So I am turning to SO-gurus for some guidance. Python 2.5 is used. Simplified version of my problem runs as follows: A bunch of scientific d...

Python NLTK figure out tense

I have a web application that translates sentences into English; the user chooses options from drop downs that basically provide the context. Now I want to turn the word and the context into an English sentence. One case is that the user chooses 'who' and 'when', 'who' could be: I, you, you two, he, she, we, they. 'When' could be: 'did ...

What is the equivalent for pycassa ColumnFamily.get_range() with Lazyboy?

I think everything is in the question. I'm looking for the Lazyboy equivalent for Pycassa ColumnFamily.get_range() -- with features like column_start, column_finish et column_count --. Thanks. ...

Return current 11-digit timestamp in Python

How can I return the current time of the local machine? This question was answered: >>import time >>time.time() >>1269888125.177495 >>int(time.time()) >>1269888125 ...

Scipy sparse... arrays?

Hey, folks. So, I'm doing some Kmeans classification using numpy arrays that are quite sparse-- lots and lots of zeroes. I figured that I'd use scipy's 'sparse' package to reduce the storage overhead, but I'm a little confused about how to create arrays, not matrices. I've gone through this tutorial on how to create sparse matrices: h...

How can I check for unused import in many Python files?

I remember when I was developing in C++ or Java, the compiler usually complains for unused methods, functions or imports. In my Django project, I have a bunch of Python files which have gone through a number of iterations. Some of those files have a few lines of import statement at the top of the page and some of those imports are not ...

how to handle an asymptote/discontinuity with Matplotlib

Hello all. Firstly - thanks again for all your help. Sorry not to have accepted the responses to my previous questions as I did not know how the system worked (thanks to Mark for pointing that out!). I have since been back and gratefully acknowledged the kind help I have received. My question: when plotting a graph with a discontinuity/...

Timezones and the DateTimeField - Django

Hi folks, I'm trying to implement a "time ago" feature, for the displaying of items on a site. As I'm caching the pages I wish to use javascript in order to render the "time ago". Javascript knows local time and problably the Timezone of the local machine so I could play with that, but that would require to hard code the server's timez...

Problem with room/screen/menu controller in python game: old rooms are not removed from memory

I'm literally banging my head against a wall here (as in, yes, physically, at my current location, I am damaging my cranium). Basically, I've got a Python/Pygame game with some typical game "rooms", or "screens." EG title screen, high scores screen, and the actual game room. Something bad is happening when I switch between rooms: the old...

How can I tell if a given login exists in my Linux box, using Python?

In Python under Linux, what is the easiest way to check the existence of a user, given his/her login? Anything better than issuing 'ls ~login-name' and checking the exit code? And if running under Windows? ...

python on apache - getting 404

I edited this question after i found a solution... i need to understand why the solution worked instead of my method? This is likely to be a silly question. I tried searching other questions that are related... but to no avail. i am running Apache/2.2.11 (Ubuntu) DAV/2 SVN/1.5.4 PHP/5.2.6-3ubuntu4.5 with Suhosin-Patch mod_python/3.3.1 ...

What is the Python equivalent of Perl's FindBin?

In perl, the FindBin module is used to locate directory of original script. What's the best way to get this directory in python? ...