python

Is there any purpose for a python application use C other than performance?

If Python was so fast as C, the latter would be present in python apps/libraries? Example: if Python was fast as C would PIL be written completely in Python? ...

Attempting to use gevent library in Python: "ImportError: cannot import name core"

I'm attempting to use the gevent library in a Python app I'm writing. However, both easy_install and installing it manually appears to be failing. Any suggestions? Python 2.6.2 (r262:71600, Aug 5 2009, 10:31:21) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>...

GAE Chat Data Persistance in Memcache

I'm writing a chat feature (like the Faceboook.com one) for a Google App Engine site. I need a way to keep track of what users have new messages. I'm currently trying to use Memcache: class Message(): def __init__(self, from_user_key, message_text) self.from_user_key = from_user_key self.message_text = message_text ...

SQLAlchemy: checking unicode string's validity for a given type of db column

Hi folks! Am developing an extract-transform-load script with sqlalchemy. Scenario is as follows: take 30+ mln text file (csv, tab-delimited or any other...). parse it and generate file, suitable for 'Load data infile' mySQL import command (as described http://dev.mysql.com/doc/refman/5.0/en/load-data.html ) From within script, disabl...

django having multiple one many to many relations that references same model

i have a model that is having multiple many to many relation to another model it is as follows: class Match(models.Model): """Model docstring""" Match_Id = models.AutoField(primary_key=True) Team_one = models.ManyToManyField('Team',related_name='Team one',symmetrical=False,) Team_two = models.ManyToManyField('Team',related_nam...

Specifying python interpreter from virtualenv in emacs

Today I've been trying to bring more of the python related modes into my emacs configuration but I haven't had much luck. First what I've noticed is that depending on how emacs is launched(terminal vs from the desktop), the interpreter it decides to use is different. launched from kde menu: M-! which python --> /usr/bin/python launche...

Numeric data collection from an mp3 in python

Anyone know how I can plot numeric data from an mp3 in real time? For example the script plays a mp3 and as its playing prints 3 sets of numeric data. ...

Get zip code based on IP Address with Python

Is it possible to find the zip code based on a users IP address using python / django (not geodjango)? I assume I would have to use a web service, but I would really like to just be able to query a database if possible. I am using geopy right now, so it would be cool if I could integrate that somehow. ...

Print out the output of os.popen() without buffering in python

Let's say that I have a process that prints out some data something like this ruby code. 1.upto(10) { |i| puts i puts "\n" sleep 0.6 } I want to have a python code that spawns this process, and read data from it to print it out. import os import sys cmd = "ruby /Users/smcho/Desktop/testit.rb"; pingaling = os.popen(...

_ElementInterface instance has no attribute 'tostring'

The code below generates this error. I can't figure out why. If ElementTree has parse, why doesn't it have tostring? http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree from xml.etree.ElementTree import ElementTree ... tree = ElementTree() node = ElementTree() node = tree.parse(open("my_xml.xml...

MySQLdb within python2.5 virtualenv

I have a Fedora 11 box with MySQL server. Fedora 11 uses python 2.6 internally and python 2.6 is automatically installed on the box. I have created a python virtual-env for version 2.5.5, so that I can run turbogears 1.x application. I have MySQLdb rpm installed on the box (and it works fine with python 2.6). When I import MySQLdb fr...

regex for Twitter username

Could you provide a regex that match Twitter usernames? Extra bonus if a Python example is provided. ...

looking for a Python based web-app to serve files

I am looking for a Python-based alternatives for AutoIndex PHP Script. Preferably it runs under WSGI. The features of AutoIndex are listed here and there is also a live demo. Note: + I'm not looking for a web server. My shared web hosting doesn't allow me to run my own background process. + Neither am I looking for web frameworks (I am...

How to use Twitter API to check if a user/password is valid?

I have a user and a password and I'd like to use Twitter API (I'm using python-twitter) to check if those are valid data. ...

First Order Logic Engine

I'd like to create an application that can do simple reasoning using first order logic. Can anyone recommend an "engine" that can accept an arbitrary number of FOL expressions, and allow querying of those expressions (preferably accessible via Python)? ...

Is there a way of checking for membership from the values of a dictionary? Once confirmed, can we do other things?

I understand that it's quite easy to check if a key is available in a dictionary, but what about certain values? So, what I have here is a dictionary of lists where the key references a set of, for consistency's sake, strings. It would look a bit like this: menu = {'breakfast':['soft-boiled eggs', 'hash brown', 'Earl Grey'], ...

QWebView not loading external CSS

I am using a QWebView to display some content and I want to use custom CSS to spruce up the output. I found that I can use the QWebSettings.setUserStyleSheetUrl() method to load my own CSS into the view. The .css file is in the same directory as my main program. self.webview = QWebView(MainWindow) self.webview.settings().setUserStyleS...

Is there a open-search solution for python?

lucene-like would be preferred. thanks ...

Remove and insert lines in a text file

I have a text file looks like: first line second line third line forth line fifth line sixth line I want to replace the third and forth lines with three new lines. The above contents would become: first line second line new line1 new line2 new line3 fifth line sixth line How can I do this using Python? ...

Using BeautifulSoup to parse lines seperated by <br> tags?

I have a page that looks like this: Company A<br /> 123 Main St.<br /> Suite 101<br /> Someplace, NY 1234<br /> <br /> <br /> <br /> Company B<br /> 456 Main St.<br /> Someplace, NY 1234<br /> <br /> <br /> <br /> Sometimes there are two rather than three "br" tags separating the entries. How would I use BeautifulSoup to parse throug...