python

Restful communication between local applications is a good idea?

I wonder if it's a good idea letting local applications (in the same server) communicate with each other entirely through Restful API? I know this is not an uncommon thing, cause we already have applications like CouchDB that is using HTTP REST for communication, even with local applications. But I want to take it to a higher level by ...

Python list: How to read the previous element when using for loop?

Possible Duplicates: Python - Previous and next values inside a loop python for loop, how to find next value(object)? Hi, everyone. I've got a list contains a lot of elements, I iterate the list using a for loop. For example li = [2,31,321,41,3423,4,234,24,32,42,3,24,,31,123] for (i in li): print i But I want to get...

Handling dates prior to 1970 in a repeatable way in MySQL and Python

In my MySQL database I have dates going back to the mid 1700s which I need to convert somehow to ints in a format similar to Unix time. The value of the int isn't important, so long as I can take a date from either my database or from user input and generate the same int. I need to use MySQL to generate the int on the database side, and ...

Python: Find the min, max value in a list

alist = [(1,3),(2,5),(2,4),(7,5)] I need to get the min max value for each position in tuple. Fox example: The exepected output of alist is min_x = 1 max_x = 7 min_y = 3 max_y = 5 Is there any easy way to do? ...

non-destructive version of pop() for a dictionary

Is there any idiom for getting an arbitrary key, value pair from a dictionary without removing them? (P3K) EDIT: Sorry for the confusing wording. I used the word arbitrary in the sense that I don't care about what I'm getting. It's different from random, where I do care about what I'm getting (i.e., I need probabilities of each item ...

Auto-load a module on python startup

I want IPython or the Python interpreter to auto-load a module when I start them. Is it possible? For example when I start IPython: $ ipython ... >>> from __future__ import division >>> from mymodule import * In [1]: Something like this. Thanks! ...

how can i convert an area code into a state using PHP or python?

I have a phone number, including area code. Is there a PHP or python-accessible API or library that will return its corresponding state? e.g. 415 -> CA. 212 -> NY. ...

linux python - can a program call itself?

I have a python program that runs a cell model continuously. when I press "A" or "B" certain functions are called - cell divide, etc. when the "esc" key is pressed the simulation exits. Is there a way for the program to exit and then restart itself when "esc" is pressed? ...

How can I change the cursor image in python soya?

Soya is a 3D game framework for python. How can I change the cursor image to/from a different image? ...

Pyqt save dom to file

Why this code does not work ? I want save dom after js execute at this page and i want use qt without gui. Sorry for my English. #coding:utf-8 from PyQt4 import QtCore, QtWebKit class Sp(): def save(self): print "call" data = self.webView.page().currentFrame().documentElement().toInnerXml() open("htm","w")....

XML parser-writer that keeps Attributes order.

I need to parse XML document and then write every node to separate files keeping exact order of attributes. So if i have input file like : <item a="a" b="b" c="c"/> <item a="a1" b="b2" c="c3"/> Output should be 2 files with every item. Now if xml.dom.minidom is used - attribute order is changed in output( i can get - <item b="b" c="...

Modifying *.RC file with python (regexp involved)

Hello guys, What I need is to parce my projects' resource files and change its version number. I have a working JS script but I would like to implement it with python. So, the problem stands in using re.sub: version = "2,3,4,5" modified_str = re.sub(r"(/FILEVERSION )\d+,\d+,\d+,\d+(\s)/g", version, str_text) I understand that becaus...

Translate `thread.start_new_thread(...)` to the new threading API

When I use the old Python thread API everything works fine: thread.start_new_thread(main_func, args, kwargs) But if I try to use the new threading API the process, which runs the thread hangs when it should exit itself with sys.exit(3): threading.Thread(target=main_func, args=args, kwargs=kwargs).start() How can I translate the cod...

Lagrange interpolation in Python

I want to interpolate a polynomial with the Lagrange method, but this code doesn't work: def interpolate(x_values, y_values): def _basis(j): p = [(x - x_values[m])/(x_values[j] - x_values[m]) for m in xrange(k + 1) if m != j] return reduce(operator.mul, p) assert len(x_values) != 0 and (len(x_values) == len(y_va...

How to build a conceptual search engine?

I would like to build an internal search engine (I have a very large collection of thousands of XML files) that is able to map queries to concepts. For example, if I search for "big cats", I would want highly ranked results to return documents with "large cats" as well. But I may also be interested in having it return "huge animals", a...

Is there Python PDF metadata writing library for Windows?

Hi, can someone point me to Python PDF package that can do metadata writing? I was surprised that I couldn't find any. I mean I found Python XMP Toolkit, but building Exempi on cygwin is nightmare I want to avoid. Thanks ...

graphical gui editor which incorporate database tables with python

(from your own experience) Is there a graphical UI editor / designer tool, commercial or free, which is able do design forms, and supports database-bound tables, before writing any line of code? PyQt Designer can't work with Databases, AFAIK (do you know how?) Dabo is the only thing so far that more or less works, but is quite heavy o...

python popularity cloud (urgent help, please)

Hi, I built a popularity cloud but it doesn't work properly. The txt file is; 1 Top Gear 3 Scrubs 3 The Office (US) 5 Heroes 5 How I Met Your Mother 5 Legend of the Seeker 5 Scrubs ..... in my popularity cloud, names are written their frequency times. For xample, Legend of the Seeker is written 5 times and their size increases. Every...

No such file or directory error

This is the error I am getting: Traceback (most recent call last): File "E:\stuff\module.py", line 91, in <module> f = open('E:/stuff/log.txt') IOError: [Errno 2] No such file or directory: 'E:/stuff/log.txt' And this is my code: f = open('E:/stuff/log.txt') The E:/stuff/log.txt file exists. I can navigate in Windows Explorer...

Replacing whitespaces within list elements

I have a list of tags: >>> tags_list ['tag1', 'second tag', 'third longer tag'] How can I replace whitespaces within each element of the list with "+" ? I was trying to do this with regular expressions but each string remains unchanged: for tag in tags_list: re.sub("\s+" , " ", tag) What is wrong with my approach ? EDIT: Yes ...