python

Removing non-english words from a sentence in python

Hi, I have written a code which sends queries to Google and returns the results. I extract the snippets(summaries) from these results for further processing. However, sometime non-english words are in these snippets which I don't want them. for example: /\u02b0w\u025bn w\u025bn unstressed \u02b0w\u0259n w\u0259n/ I only want the "uns...

Django and MongoDB Engine - Problem with object IDs!

Hi folks, I'm using Django 1.3beta and django-mongodb-engine for database backend. Problem is when I save an object with a pk set I get this error: /usr/local/lib/python2.6/dist-packages/django/db/models/fields/__init__.pyc in get_prep_lookup(self, lookup_type, value) 290 return value 291 elif lookup_type i...

what is the fastest way to update thousands rows in mysql

lets assume you have a table with 1M rows and growing ... every five minutes of every day you run a python programm which have to update some fields of 50K rows my question is: what is the fastest way to do the work? runs those updates in loop and after last one is executed than fire up a cursor commit? or generate file and than ru...

Using the ALT key with PyGame

Hi guys, I'm looking to detect the ALT key in PyGame, but every time I press it, it will bring up the menu that you normally get if you click the icon at the upper left of the window (Restore, Maximize, etc). How do I get PyGame to recognise the keypress, rather than the window? many thanks ...

slow File Processing in python

Hello All, I am trying a file operation using python.Aim is to continuously read a file of size(100bytes),pack and send them through socket. These files are read from a directory. Problem: when i run the program continuously, execution time is increasing. Initially, execution time is less than a second; later it reaches till 8~10second...

Is python logger thread-safe or not?

Is python logger thread-safe or not? I use python 2.6. ...

Changing the key name of an entity

I understand that they are not supposed to be changed, this is somewhat of a schema migration and only a one-time thing. I would like to change the key names of entities in my Google App Engine application, effectively deleting and re-crating an entity and updating all references to it. What is the best way to do this? I'm interesting ...

python hex hmac md5 of passwords not matching javascript

hi all i have a javascript password coder md5 = hex_hmac_md5(secret, password) How can i emulate this in python - ive tried md5 but that is not the same value i got my md5 javascript code from this website: Pajs Home (md5.js) He states the use is as follows: In many uses of hashes you end up wanting to combine a key ...

Closing Perspective Broker connection in Twisted

Hi! I have program which has servers interacting with each other using Twisted's remote procedure calls, and I run in problems with closing connections when they are not needed anymore. Connections should be able to close itself in both sides. Case 1: How do I close connection in connecting part? factory = pb.PBClientFactory() reactor...

Python: 'import node.py' raises "No module named py"-error

I have a file main.py like this: import node.py [my code...] and a node.py like this: [more of my code] When executing main.py, I get this error: File "/home/loldrup/repo/trunk/src/src/main.py", line 2, in <module> import node.py ImportError: No module named py ...

How to find all words that have the same appearence in two different languages?

The russian alphabet includes many letters that are the same in the English alphabet. Here is the list of common letters: L='acekopuxy' Now, given two huge lists R and E, each in the form [word_A, word_B, ...], where each word_N is a lowercase word, I want to create a list C, which should contain only those words that have the same sp...

Stopping an application (punjab) that is run using Twisted

I am trying to run punjab connection manager with very less python knowledge. I followed the punjab docs and can start the application. But how do I stop/restart it ? twistd -y punjab.tac starts punjab first time but after that if I enter the same command , it says Another twistd server is running, PID 3726. Precisely I want to se...

capitalization of library class names

Why do collection.defaultdict and collection.OrderedDict have different capitalizations? Is there some subtle difference that I should be aware of? (P3K) ...

Can twisted be implemented in Java?

I remember reading that the following features lead to the development of interesting frameworks/libraries in Python:- (I read the article from http://www.python.org/workshops/2002-02/papers/09/index.htm) A simple class model, which facilitates inheritance. Dynamic typing, which means that the code needs to assume less. Built-in memory...

Python logic in assignment

Given that secure is a boolean, what do the following statements do? Especially the first statement. (1) protocol = secure and "https" or "http" (2) newurl = "%s://%s%s" % (protocol,get_host(request),request.get_full_path()) ...

3rd party applications inside iFrames?

I am about to build a web application and I want to allow other developers extend it with their own applications. Should I do this with iFrames like Facebook? Is this a good practice? Are there other alternatives that let other developers extend my application (that is for the user it looks like it's from my application). To be speci...

Is it safe to use SQLalchemy with gevent?

I know that some database drivers and other libraries providing connection to external services are incompatible with coroutine-based network libraries. However, I couldn't find out if SQLAlchemy can be safely used with such libraries (namely, gevent), and if any workarounds should be applied to exclude possible errors. Can you either t...

PHP front-end for installing Django

A simple question: Is this possible? Is it worth the time looking into it? ...

How to limit program's execution time when using subprocess?

I want to using subprocess to run a program, but I need to limit the execution time. For example, if it runs more than 2 seconds, I want to kill it. For common programs, kill() works well. But if I try to run "/usr/bin/time something", kill() can't really kill the program. But my code below seems not works well, the program is still ru...

Handling lazy JSON in Python - 'Expecting property name'

Using Pythons (2.7) 'json' module I'm looking to process various JSON feeds. Unfortunately some of these feeds do not conform with JSON standards - in specific some keys are not wrapped in double speech-marks ("). This is causing Python to bug out. Before writing an ugly-as-hell piece of code to parse and repair the incoming data, I tho...