python

Scaling disqus using Django, horizontal and vertical partitioning helper methods, please explain

http://www.slideshare.net/zeeg/djangocon-2010-scaling-disqus Vertical partitioning helper: class ApplicationRouter(object) def db_for_read(self, model, **hints): instance = hints.get('instance') if not instance: return None app_label = instance._meta.app_label return get_application_...

Python/Tkinter: Mouse drag a window without borders, eg. overridedirect(1)

Any suggestions on how one might create event bindings that would allow a user to mouse drag a window without borders, eg. a window created with overridedirect(1)? Use case: We would like to create a floating toolbar/palette window (without borders) that our users can drag around on their desktop. Here's where I'm at in my thinking (ps...

Relational database design - Two Relations 1:1 or one 1:2 ?

Hello everyone! This question is about how to design a SQL relationship. I am pretty newbie in this matter and I'd like to know the answers of (way) more experts guys... I am currently migrating a ZopeDB (Object oriented) database to MySQL (relational) using MeGrok and SqlAlchemy (although I don't think that's really too relevant, sinc...

Lists in pgu/pygame

Hi, I'm searching for help about lists in pgu gui for pygame. I need to know which methods and properties they have, so I can include them in my programs ...

Need help with KeyError when building epydoc files for project

I have a pylons project with an extensive set of functional tests that I want my manual QA's to be able to read from time to time, so I'm using epydoc to build out the html pydocs on the functional test modules. It seems to be working fine. It generates the docs, and I can navigate through them without any apparent problems. However, ...

Assigning a value to an element of a slice in Python

This is a simple question about how Python handles data and variables. I've done a lot of experimenting and have Python mostly figured out, except this keeps tripping me up: [edit: I separated and rearranged the examples for clarity] Example 1: >>> a = [[1], 2] >>> a[0:1] [[1]] >>> a[0:1] = [[5]] >>> a [[5], 2] # The assignment worked...

"Add another" popup with django-ajax-selects

I try to use django-ajax-selects in a form used in a view (not in the admin). I sucessfully get the autocomplete field working (with lookup), but I don't know how to add the "+" button to add a new record. My current code looks like: -- models.py class Address(models.Model): partner = models.ForeignKey(Partner, related_name='addre...

Unit testing with django-celery?

I am trying to come up with a testing methodology for our django-celery project. I have read the notes in the documentation, but it didn't give me a good idea of what to actually do. I am not worried about testing the tasks in the actual daemons, just the functionality of my code. Mainly I am wondering: How can we bypass task.delay(...

Strange newline when attempting unbuffered reading in python

I have this code: def getch(self): if os.name == 'posix': fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(fd) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) elif os.name == 'nt': ch = m...

String error in my python api wrapper class

I'm writing an API wrapper to a couple of different web services. I have a method that has an article url, and I want to extract text from it using alchemyapi. def extractText(self): #All Extract Text Methods ---------------------------------------------------------// #Extract page text from a web URL (ignoring navigation links...

In Django's template engine, how do I display a datetime object in a meaningful way?

{{ p.date }} is displayed as: Date: 2010-10-29 21:56:39.226000 How do I make changes to how that's displayed? ...

When I do Geospatial querying in MongoDB, how do I also return the distance from my desired point?

for post in db.datasets.find({"loc":{"$near":[50,50]}}).limit(10): How do I get the distance between the document and "50,50"? ...

[Python] Extracting data from a URL result with special formating

I have a URL: http://somewhere.com/relatedqueries?limit=2&query=seedterm where modifying the inputs, limit and query, will generate wanted data. Limit is the max number of term possible and query is the seed term. The URL provides text result formated in this way: oo.visualization.Query.setResponse({version:'0.5',reqId:'0',status:'...

Need help programming Facebook application!!

Now i tried thousands of codes, to get my visitors to see a "authentication sign" where i can get access to their walls. but i can't get that to be visible!! everytime i try taking my application from iframe to FBML it says: "The application you are trying to access does not exist or has been disabled." Can you even get them to authentic...

python ctypes.create_string_buffer help!!!!

hey all, i have been scanning the net for answers to this question for days now and im still making no progress so i beg for your help oh mighty guru's of computer wisdom :) my problem is my readprocessmemory function is returning unicode.. here is my code kernel32 = ctypes.windll.kernel32 PROCESS_QUERY_INFORMATION = 0x0400 PROCESS_VM_...

What is the easiest way to make an optional C extension for a python package?

I've created a C extension that I'd like to enable in my Python package (using setuptools) only if a command line option is passed in. What is the easiest way to do this? I can't seem to find any straightforward ways of going about this. ...

python getting weekday from an input date.

Hi I'm trying to work on a homework problem where I have an input date in the format YYYY-MM-DD I need to import a couple modules and create a function weekday where it splits up the date and returns the weekday. So far I imported: from time import * from datetime import * I need help in my weekday function where I must use a .spl...

How to declare array of zeros in python (or an array of a certain size)

I am trying to build a histogram of counts... so I create buckets. I know I could just go through and append a bunch of zeros i.e something along these lines: buckets = []; for i in xrange(0,100): buckets.append(0); is there a more elegant way to do it? I feel like there should be a way to just declare an array of a certain size....

When should I use escape and safe in Django's template system?

If I have a box where people put comments, and then I display that comment like this...should I escape? {{ c.title }} ...

CherryPy Logging: How do I configure and use the global and application level loggers?

Hello all. I'm having trouble with logging. I'm running CherryPy 3.2 and I've been reading through the docs here, but haven't found any examples of how to configure a local log file for output and how to write to it. Raspberry.py: import socket import sys import cherrypy app_roots = { # Sean's laptop dev environmen...