python

Efficient substring searching in Python with MySQL

I'm trying to implement a live search for my website. One that identifies words, or parts of a word, in a given string. The instant results are then underlined where they match the query. For example, a query of "Fried green tomatoes" would yield: SELECT * FROM articles WHERE (title LIKE '%fried%' OR title LIKE '%green%' OR ...

How can I query for records based on an attribute of a ReferenceProperty? (Django on App Engine)

If I have the following models in a Python (+ Django) App Engine app: class Album(db.Model): private = db.BooleanProperty() ... class Photo(db.Model): album = db.ReferenceProperty(Album) title = db.StringProperty() ...how can I retrieve all Photos that belong to a public Album (that is, an Album with private == False)? To fu...

pydev not recognizing python installation with django

I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be? ...

Constipated Python urllib2 sockets

I've been scouring the Internet looking for a solution to my problem with Python. I'm trying to use a urllib2 connection to read a potentially endless stream of data from an HTTP server. It's part of some interactive communication, so it's important that I can get the data that's available, even if it's not a whole buffer full. There se...

Python execution speed: laptop vs desktop

I am running a program that does simple data processing: parses text populates dictionaries calculates some functions over the resulting data The program only uses CPU, RAM, and HDD: run from Windows command line input/output to the local hard drive nothing displayed on or printed to screen no networking The same program is run o...

Python filter / max combo - checking for empty iterator

(Using Python 3.1) I know this question has been asked many times for the general question of testing if iterator is empty; obviously, there's no neat solution to that (I guess for a reason - an iterator doesn't really know if it's empty until it's asked to return its next value). I have a specific example, however, and was hoping I ca...

Dmoz taxonomy hierarchy download

Hi, I want all the dmoz categories hierarchy. Is there a script to get this? Or is this dataset already available? Thank you ...

Resetting all global internal state of the net-snmp library from the Python bindings

I'm trying to create automated integration tests for this hardware+software test subject which runs a SNMP agent as it's command interface. Our test setup looks like this: We're using Fitnesse as a test runner and PyFit to be able to write the tests in Python. We then use netsnmp with Python bindings to send SNMP commands. This works pre...

exhausted iterators - what to do about them?

(In Python 3.1) (Somewhat related to another question I asked, but this question is about iterators being exhausted.) # trying to see the ratio of the max and min element in a container c filtered = filter(lambda x : x is not None and x != 0, c) ratio = max(filtered) / min(filtered) It took me half hour to realize what the problem is ...

Is it technically possible to take a screenshot of a website programmatically?

Do you think is technically possible to take a screeshot of a website programmatically? I would like to craft a scheduled Python task that crawls a list of websites taking an homepage screenshot of them. Do you think is technically feasible or do you know third party website that offer a service like that (Input: url --> Output: screen...

How can I reverse a list in python?

How can i do this in python? array=[0,10,20,40] for (i = array.length() - 1 ;i >= 0; i--) I need to have the elements of an array but from the end to the beginning. ...

Is there a better way to do this in Python?

ids = [] for object in objects: ids += [object.id] ...

ImportError when installing NumPy for Python 2.7

EDIT: after reading this http://projects.scipy.org/numpy/ticket/1322 it seems that the NumPy version I am using doesn't work with Mac OS 10.5.x. Does anyone have access to a version of NumPy that works with Mac OS 10.5? I can't get it to compile either. Original post ... I am trying to use NumPy, but I'm having difficulty installing ...

PyTable Column Order

Is there a way to create a PyTable with a specific column order? By default, the columns are alphabetically ordered when using both dictionary or class for schema definition for the call to createTable(). My need is to establish a specific order and then use numpy.genfromtxt() to read and store my data from text. Unfortunately, my text ...

How to split this string with python?

I have strings that look like this example: "AAABBBCDEEEEBBBAA" Any character is possible in the string. I want to split it to a list like: ['AAA','BBB','C','D','EEEE','BBB','AA'] so every continuous stretch of the same characters goes to separate element of the split list. I know that I can iterate over characters in the string, che...

How to control the msn messager's "personal message" displayed to others by python?

How to control the msn messager's "personal message" displayed to others by python? Want to share some private infomation remotely with this area. ...

Why Python sets my default timezone to -1?

I use Python to track the version between local SQLite and remote web page. It is useful to compare them by Last-modified and file size information from the HTTP response. I found something interesting during development. def time_match(web,sql): print web,sql t1 = time.strptime(web,"%a, %d %b %Y %H:%M:%S %Z") t2 = time.strptime(s...

noob question regarding twitter oauth

Hey guys, I'm unfamiliar with the new oauth system. I wanted to crawl the status updates of my friends, and their friends' (if permissions allow) with my specified account credentials using the python-twitter api. With the new oauth authentication, does it means that I have to first register an application with twitter before I can us...

how the bittorent is compiled to exe

As all know bittorrent is written in python program. whenever i download and install the bittorrent.exe, I never found any file(like dll etc) associated in program files i mean whenever i go to c:\program files\bittorrent i found only single file called bittorrent.exe, i wonder how this program is compiled to exe , whereas whenever i wan...

Python - HTML Parsing with Tidy

This code takes a bit of bad html, uses the Tidy library to clean it up and then passes it to an HtmlLib.Reader(). import tidy options = dict(output_xhtml=1, add_xml_decl=1, indent=1, tidy_mark=0) from xml.dom.ext.reader import HtmlLib reader = HtmlLib.Reader() doc = reader.fromString...