python

Jython/Grinder/Grinderstone: self arg can't be coerced to net.grinder.plugin.http.HTTPUtilities

A grinder script i have been building out for the past few days has been working pretty well up until just now. I am getting a runtime error initially saying: self.token___LASTFOCUS = HTTPUtilities.valueFromHiddenInput('__LASTFOCUS') TypeError: valueFromHiddenInput(): expected 2-3 args; got 1 so i added [another arg][1], so...

How do I count words in an nltk plaintextcorpus faster?

I have a set of documents, and I want to return a list of tuples where each tuple has the date of a given document and the number of times a given search term appears in that document. My code (below) works, but is slow, and I'm a n00b. Are there obvious ways to make this faster? Any help would be much appreciated, mostly so that I ca...

resources for learning 3D basics (Python / JavaScript)

While I consider myself a reasonably competent programmer, I have no experience with even the most basic graphics programming. Are there any recommended resources for learning the basics of 3D programming - preferably using a high-level language like Python or JavaScript? Ideally, I'd like a simple hello world example in canvas or WebG...

findPattern() Python Code...not executing correctly?

Hi all, my homework assignment was to: "write a function called findPattern() which accepts two strings as parameters, a filename and a pattern. The function reads in the file specified by the given filename and searches the file’s contents for the given pattern. It then returns the line number and index of the line where the first inst...

How can Python access the X11 clipboard?

I want my Python script to be able to copy and paste to/from the clipboard via x11 (so that it will work on Linux). Can anyone point me to specific resources I can look at, or the concepts I would have to master? Is this possible to do with the Python X library at http://python-xlib.sourceforge.net ? ...

Converting flat sequence to 2d sequence in python

I have a piece of code that will return a flat sequence for every pixel in a image. import Image im = Image.open("test.png") print("Picture size is ", width, height) data = list(im.getdata()) for n in range(width*height): if data[n] == (0, 0, 0): print(data[n], n) This codes returns something like this ((0, 0, 0), 1250) (...

Jython test coverage

I'm trying to use Jython instead of Python for a project (want jdbc driver for a sort of rare database). Everything is working OK so far, but I can't find any good tools for code coverage. Does anyone have a solution to this? The googling I've done seems to indicate that jython is missing some things that code coverage tools need. http:...

Converting while to generator 3.4 times slow down

What is happening? Can somebody explain me what happens here, I changed in tight loop: ## j=i ## while j < ls - 1 and len(wordlist[j]) > lc: j+=1 j = next(j for j in range(i,ls) if len(wordlist[j]) <= lc) The commented while version ran the whole program: 625 ms, the next generator version ran the wh...

Can't *copy* an index from list to another with a twist in Python

I'm pretty new to python and am trying to grab the ropes and decided a fun way to learn would be to make a cheesy MUD type game. My goal for the piece of code I'm going to show is to have three randomly selected enemies(from a list) be presented for the "hero" to fight. The issue I am running into is that python is copying from list to l...

Python: Google Checkout Signature Function

I am attempting to integrate Google Checkout into my website. I have created the following function for generating the hmac-sha-1 signature requred: def make_signature(cart_xml): import hmac import hashlib import base64 # The number is a psuedo-merchantID, cart_xml contains a string with the # shopping cart xml as o...

Python, is it proper for one thread to spawn another

I am writing an update application in Python 2.x. I have one thread (ticket_server) sitting on a database (CouchDB) url in longpoll mode. Update requests are dumped into this database from an outside application. When a change comes, ticket_server triggers a worker thread (update_manager). The heavy lifting is done in this update_manager...

How do I dump the TCP client's buffer in order to accept more data?

I've got a simple TCP server and client. The client receives data: received = sock.recv(1024) It seems trivial, but I can't figure out how to recieve data larger than the buffer. I tried chunking my data and sending it multiple times from the server (worked for UDP), but it just told me that my pipe was broken. Suggestions? ...

Convert Python List to Column in CSV

I have a list of values (v1, v2, v3) and I want to write these to a column called VALUES in a csv. I'm using csvreader and csvwriter to get as far as I have. I've only figured out how to write them to rows using csvwriter.writerow. ...

error message when populating cell in 2d numpy array

I am trying to populate data from some csv files into a numpy array with the following code: PreExArray=zeros([len(TestIDs),numColumns],float) for row in reader: if row[1] =='PreEx10SecondsBEFORE': PreExArray[(j-1),0]=[row[2]] However, the last line of code above throws the following error: ValueError: setting an array e...

How to get out of interactive mode in Python

This obviously an extremely novice question, but I've installed Python 2.7 and started reading the manual. However I looked and looked, and couldn't understand how to start programming a file rather than writing in interactive mode. One book that was online suggested quit(), which surprise -- quit the program. Should coding be done in a...

Capturing output from buffered StdOut program

I'm trying to capture the output of a windows program using Qt and Python. I'm starting the process with QProcess, but the problem is the output is being buffered. Unfortunately I don't have access to the source, and therefore can't flush the output. From my searching around, I found the program "Expect", but I don't know if there is...

Python trouble with repeater

Im trying to write a program so that I get a result of... 5 : Rowan 6 : Rowan 7 : Rowan 8 : Rowan 9 : Rowan 10 : Rowan 11 : Rowan 12 : Rowan I want to be able to set it so that I can change the starting number, the amount of times it repeats and the word that it repeats. this is what i have so far... def hii(howMany, start, Word): ...

How to know which row a user selects from an HTML table - GAE Python

Sorry if this is a newbie question. I have searched but found nothing... Using Python on GAE, I will display a table of, say, customers on an HTML table. The table will show their name and phone number. I want the user to double-click on a row and have the python Post() method know either the row number double-clicked or the customer...

Apply opencv threshold to a numpy array

I'm trying to apply opencv's Threshold function to a numpy array. I'm using the python bindings for opencv 2.1. It goes like this: import cv import numpy as np a = np.random.rand(1024,768) cv.Threshold(a,a,0.5,1,cv.CV_THRESH_BINARY) and this throws an error: OpenCV Error: Unsupported format or combination of formats () in threshold ...

Taking list's tail in a Pythonic way?

Hi. Suppose we have: from random import randrange data = [(randrange(8), randrange(8)) for x in range(8)] And we have to test if the first item equals to one of a tail. I am curious, how we would do it in most simple way without copying tail items to the new list? Please take into account this piece of code gets executed many times in...