python

Problem Install and Run psycopg2 + Windows + Apache2 + mod_wsgi

1) I try to setup a new web environment to host python + psycopg2 code. Here are my steps : 2) Download http://modwsgi.googlecode.com/files/mod_wsgi-win32-ap22py26-3.0.so 3) Copy mod_wsgi-win32-ap22py26-3.0.so to C:\Program Files\Apache Software Foundation\Apache2.2\modules, and rename it as mod_wsgi.so Add the following new lines int...

Convert C++ to Python (For Loop multiple assignment)

Convert to python: #include <iostream> using namespace std; int main(int argc, char** argv) { for (int i = 0, j = i + 3; i < 100; ++i, j= i+3) cout << i << " j: " << j << endl; getchar(); return 0; } I try: for i in range(99): j = i + 3 print i, " j: ", j How to make it one for loop? ...

Single linked list in Python, how to write pop and push.

I am trying to code a class that makes use of Push and Pop from a stack (with single linked list). I am not sure how to write the push and pop functions. Please help me, I really need a simple example written in Python with the following functions. Push Pop ifEmpty ...

Sweave for python

I've recently started using Sweave* for creating reports of analyses run with R, and am now looking to do the same with my python scripts. I've found references to embedding python in Sweave docs, but that seems like a bit of a hack. Has anyone worked out a better solution, or is there an equivalent for python I'm not aware of? * Swea...

Send/Receive sms using AT command from fedora in python Application

hai guys Can any one help me to send and receive sms using AT command in python application Os: fedora 8 which phone will be better with linux(nokia,sony ericson,samsung,.....)? In that which all phone will support send /receive sms using AT command? ...

Multiple consumers & producers connected to a message queue, Is that possible in AMQP?

I'd like to create a farm of processes that are able to OCR text. I've thought about using a single queue of messages which is read by multiple OCR processes. I would like to ensure that: each message in queue is eventually processed the work is more or less equally distributed an image will be parsed only by one OCR process An OCR pr...

Language detection in python

Possible Duplicate: Is there a Python library/class that can take a piece of text and determine the language? How to detect the language of user submitted text (some keywords shorter than 30 chars in this case) natively in Python? One method is to use Google AJAX Language API (Python Wrapper for Google AJAX Language API). I'm...

Send AT-command through bluetooth from python application

hai guyz, how can i send AT-command through bluetooth from a python application? OS:fedora 8 Any one please healp me with the code? which package i need to import? from where can i download it? ...

How to redirect stdout for a subprocess?

def StartProc(dir, parm): global proc proc_log = open(dir + os.sep + "MyLog.txt","w") #new path for each file if parm: proc = subprocess.Popen(path, 0, None, subprocess.PIPE, proc_log, None) else: MyReset(proc) #reset the process(proc) to its default values proc.stdout = ...

JSON python to javascript

I want to transfer some data from python to javascript. I use Django at python side and jQuery at javascript side. The object I serialize at python side is a dictionary. Besides simple objects like lists and variables, this dictionary contains instances of SomeClass. To serialize those instances I extendeded simplejson.JSONEncode like...

Regex to seperate Numeric from Alpha

I have a bunch of strings: "10people" "5cars" .. How would I split this to? ['10','people'] ['5','cars'] It can be any amount of numbers and text. I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it in Python. ...

HTML parser for GAE

Generally I use lxml for my HTML parsing needs, but that isn't available on Google App Engine. The obvious alternative is BeautifulSoup, but I find it chokes too easily on malformed HTML. Currently I am testing libxml2dom and have been getting better results. Which pure Python HTML parser have you found performs best? My priority is th...

Executing multiple commands using Popen.stdin

I'd like to execute multiple commands in a standalone application launched from a python script, using pipes. The only way I could reliably pass the commands to the stdin of the program was using Popen.communicate but it closes the program after the command gets executed. If I use Popen.stdin.write than the command executes only 1 time o...

Django and Postgres transaction rollback.

I have a piece of code that works in a background process which looks like from django.db import transaction try: <some code> transaction.commit() except Exception, e: print e transaction.rollback() In a test, I break <some_code> with data that causes a database error. The exception is following File "/home/comm...

How to count the frequency of the elements in a list?

I'm a python newbie, so please bear with me. I need to find the frequency of elements in a list a = [1,1,1,1,2,2,2,2,3,3,4,5,5] output-> b = [4,4,2,1,2] Also I want to remove the duplicates from a a = [1,2,3,4,5] ...

which is a minimalistic python wsgi development server with support for code reload ?

From what I can tell wsgiref - no code reload CherryPy - more than just the server mod_wsgi - all the apache overhead paste.httpserver - paste is a huge package with other stuff in it flup - same as paste, too much stuff. Spawning - never used it but seems lightweight enough. Tornado - not really wsgi + full "framework" Werkzeug - run...

Calling gnuplot from python

I've a python script that after some computing is a generating two data files formatted as gnuplot input. How do I 'call' gnuplot from python ? I want to send the following python string as input to gnuplot: "plot '%s' with lines, '%s' with points;" % (eout,nout) where 'eout' and 'nout' are the two filenames. PS: I prefer not to use...

How to set timeout for urlfetch in Google App Engine?

I'm trying to have Django (on top of GAE) fetch data from another web service. I'm often hit with error like this: ApplicationError: 2 timed out Request Method: GET Request URL:http://localhost:8080/ Exception Type: DownloadError Exception Value: ApplicationError: 2 timed out Exception Location: /google_...

Library like fakeweb for Python

I really like the way fakeweb in Ruby can be used to fake http requests when testing. Is there a similar library or an alternative for Python? ...

Getting DISTINCT users on Google App Engine

How to do this on Google App Engine (Python): SELECT COUNT(DISTINCT user) FROM event WHERE event_type = "PAGEVIEW" AND t >= start_time AND t <= end_time Long version: I have a Python Google App Engine application with users that generate events, such as pageviews. I would like to know in a given timespan how many unique users genera...