python

Is test suite deprecated in PyUnit?

Following the example in PyUnit, I came up with the following unittest code that works fine. import unittest class Board: def __init__(self, x, y): self.x = x; self.y = y; def __eq__(self, other): return self.x == other.x and self.y == other.y class BoardTest(unittest.TestCase): def setUp(self): self.b10_10 ...

Python threading unexpectedly slower

I have decided to learn how multi-threading is done in Python, and I did a comparison to see what kind of performance gain I would get on a dual-core CPU. I found that my simple multi-threaded code actually runs slower than the sequential equivalent, and I cant figure out why. The test I contrived was to generate a large list of random ...

convert a python code to a perl code

can you convert this python code to perl code (i search about it but dont find a good result) for i in xrange(20): try: instructions except : pass Thanks ...

Error with urlencode in python

I have this: a = {'album': u'Metamorphine', 'group': 'monoku', 'name': u'Son Of Venus (Danny\xb4s Song)', 'artist': u'Leandra', 'checksum': '2836e33d42baf947e8c8adef48921f2f76fcb37eea9c50b0b59d7651', 'track_number': 8, 'year': '2008', 'genre': 'Darkwave', 'path': u'/media/data/musik/Leandra/2008. Metamorphine/08. Son Of Venus (Danny\xb4...

Cosine Similarity of Vectors of different lengths?

I'm trying to use TF-IDF to sort documents into categories. I've calculated the tf_idf for some documents, but now when I try to calculate the Cosine Similarity between two of these documents I get a traceback saying: #len(u)==201, len(v)==246 cosine_distance(u, v) ValueError: objects are not aligned #this works though: cosine_distan...

how to serve PHP together with Django?

i have a Bluehost hosting account, and i manually configure django with this tutorial, but now i need to run php scripts into a subdomain or in subfolder, how can i do that? my root .htaccess look like this AddHandler fcgid-script .fcgi # For security reasons, Option followsymlinks cannot be overridden. #Options +FollowSymLinks Options...

Optimizing appengine entity key usage

Should I care about locality of entities on the Google App Engine datastore? Should I use custom entity key names for that? For example, I could use "$article_uuid,$comment_id" as the key name of a Comment entity. Will it improve the speed of fetching all comments for an article? Or is it better to use shorter keys? Is it a good practi...

Math in python - converting data files to matrices

Hello! Today, as I tried to put together a script in Octave, I thought, this may be easier in python. Indeed the math operators of lists are a breeze, but loading in the file in the format is not as easy. Then I thought, it probably is, I am just not familiar with the module to do it! So, I have a typical data file with four columns ...

Using urllib2 with Jython 2.2

I'm working with a product that has a built-in Jython 2.2 instance. It comes with none of the Python standard libraries. When I run this instance of Jython, the default path is ['./run/Jython/Lib', './run/Jython', '__classpath__'] I added all of the .py module files from Python 2.2 to the ./run/Jython/Lib directory, and I am able t...

How i can get a response with xmpp client in python

Hi, i'm using xmpp in python, and i can send messages but how i can receive? ...

Invoke make from different directory with python script

I need to invoke make (build a makefile) in a directory different from the one I'm in, from inside a Python script. If I simply do: build_ret = subprocess.Popen("../dir1/dir2/dir3/make", shell = True, stdout = subprocess.PIPE) I get the following: /bin/sh: ../dir1/dir2/dir3/make: No such file or directory I've tr...

web2py: how to enable "request_reset_password" function?

Hello, I'm new to web2py but eager to learn it fast. I try to enable "request_reset_passwor" function but every time I enter this page: http://127.0.0.1:8000/project/default/user/request_reset_password I receive message that the function is disabled. Can you please tell me what should I do and where to get it working? Thank you ...

Python multiprocessing.Queue deadlocks on put and get

I'm having deadlock problems with this piece of code: def _entropy_split_parallel(data_train, answers_train, weights): CPUS = 1 #multiprocessing.cpu_count() NUMBER_TASKS = len(data_train[0]) processes = [] multi_list = zip(data_train, answers_train, weights) task_queue = multiprocessing.Queue() done_queue = mu...

Scraping sites that require login with Python

I use several ad networks for my sites, and to see how much money I made I need to log in to each daily to add up the values. I was thinking of making a Python script that would do this for me to get a quick total. I know I need to do a POST request to log in, then store the cookies that I get back and then GET request the report page wh...

Which Python should I use?

Possible Duplicates: Is it advisable to go with Python 3.1 for a beginner? What version of Python should I use if Im a new to Python? Haven't really made anything in Python... Which Python should I take ahold of? 2.X or 3.X? ...

Make django admin logEntry read only?

I found this post and it was very useful, but i need put the logEntry model into read-only in the admin interface, its that possible? thanks and sorry for my english! ...

python implementation of patricia tries

Looking around for python implementations of tries just so that I can understand what they are and how they work, I came across Justin Peel's patricia trie and found it very instructive: it's straightforward enough for one as new as I am to play around with it and learn from it. However there's something I think I'm not understanding: ...

Python sort (list/tuple) in list

I have some data either in list contains lists, or list contains tuples. data = [[1,2,3], [4,5,6], [7,8,9]] data = [(1,2,3), (4,5,6), (7,8,9)] And I want to sort by the 2nd element in the subset. Meaning, sorting by 2,5,8 where 2 is from (1,2,3), 5 is from (4,5,6). What is the common way to do this? Should I store tuples or lists in m...

Drawing an anti-aliased line with thePython Imaging Library

I'm drawing a bunch of lines with the Python Imaging Library's ImageDraw.line(), but they look horrid since I can't find a way to anti-alias them. How can I anti-alias lines in PIL? If PIL can't do it, is there another Python image manipulation library that can? ...

Python how to read and split a line to several integers

For input file separate by space/tab like: 1 2 3 4 5 6 7 8 9 How to read the line and split the integers, then save into either lists or tuples? Thanks. data = [[1,2,3], [4,5,6], [7,8,9]] data = [(1,2,3), (4,5,6), (7,8,9)] ...