python

Simple question about numpy matrix in python

Let's suppose I have a numpy matrix variable called MATRIX with 3 coordinates: (x, y, z). Is acessing the matrix's value through the following code myVar = MATRIX[0,0,0] equal to myVar = MATRIX[0,0][0] or myVar = MATRIX[0][0,0] ? What about if I have the following code? myTuple = (0,0) myScalar = 0 myVar = MATRIX[myTuple, myS...

How do I send and receive real-time signals `sigqueue()` in Python?

Python provides a signals module and os.kill; does it have a facility for sigqueue() (real-time signals with attached data)? What are the alternatives? ...

Is RLock a sensible default over Lock?

Dear all, the threading module in Python provides two kinds of locks: A common lock and a reentrant lock. It seems to me, that if I need a lock, I should always prefer the RLock over the Lock; mainly to prevent deadlock situations. Besides that, I see two points, when to prefer a Lock over a RLock: RLock has a more complicated intern...

How to send status to the VIM status line after calling custom VIM (Python) function

I've just created my first VIM script, I wrote it in Python. It's a simple script to switch color schemes from a directory (/vim/etc/colors). I would like to know how to send a notification after the color scheme changed with the name of the selected color scheme to the vim 'statusline'. rson gave an answer to my question, here is an up...

Python integer to read-only buffer

I am using cdb for a constant database in python. I would like to associate integer id's with some strings, and I would like to avoid storing each of these integer id's as strings, and instead store them as an integer. cdb though is looking for either a string or a read only buffer. Is there a way that I can store these keys as intege...

Parsing dates from free-text input in Python

I'm about to start working on a simple calendar app for a website I'm working on (using Django, but that fact's probably not relevant). I'd like users to be able to enter when an event is in a text box like this: Every Sunday evening at 7pm Next Friday Tuesday 1st Dec 2009 and have my application begin to make some guesses as to whe...

Creating an autologin program with Python

I don't know what the objects name is because I don't have the source code for it but I want to code something in Python to have it login to an application for me. Basically I want it to start the program which is this import subprocess subprocess.call(['C:\Program Files\PATH\program.exe']) But than I want it to click on the login b...

how to print number with commas as thousands separators in Python 2.x

I am trying to print an integer in Python 2.6.1 with commas as thousands separators. For example, I want to show the number 1234567 as "1,234,567". How would I go about doing this? I have seen many examples on Google, but I am looking for the simplest practical way. It does not need to be locale-specific to decide between periods and co...

Can I find all of a certain base model in App Engine?

Given a class-like relationship: class A(db.Model): pass class B(A): pass Can I get all of the base class? The query: models.A.all().fetch(1) returns an empty list. ...

Optimized method for calculating cosine distance in Python

I wrote a method to calculate the cosine distance between two arrays: def cosine_distance(a, b): if len(a) != len(b): return False numerator = 0 denoma = 0 denomb = 0 for i in range(len(a)): numerator += a[i]*b[i] denoma += abs(a[i])**2 denomb += abs(b[i])**2 result = 1 - numerator / (sqrt(den...

What's the best way to divide large files in Python for multiprocessing?

I run across a lot of "embarrassingly parallel" projects I'd like to parallelize with the multiprocessing module. However, they often involve reading in huge files (greater than 2gb), processing them line by line, running basic calculations, and then writing results. What's the best way to split a file and process it using Python's multi...

Set and use flags against a users profile model in Django.

I have a simple webapp in Django for an iPhone app. I want to prompt the user to review our product, but just once. I then don't want to show that prompt again. So would the best practise way of implementing this to be to add a new entry to the user profile model with a bolean field: "reviewed" - and then set that flag when the user com...

Debugging Pyparsing Grammar

I'm building a parser for an imaginary programming language called C-- (not the actual C-- language). I've gotten to the stage where I need to translate the language's grammar into something Pyparsing can accept. Unfortunatly when I come to parse my input string (which is correct and should not cause Pyparsing to error) it's not parsing ...

which is a better language (C++ or Python) for complex problem solving exercises (ex. Graphs) ?

I am trying to work on some problems and algorithms. I know C++ but a friend told me that it would be better if done with Python.As it would be much faster to develop and less time is spent in programming details which does not actually earn anything solution wise. EDIT 2: I plan to use python-graph lib from Google-codes, Please provide...

merge background audio file

I have 2 audio files for primary and background music that I want to merge (not concatenate). The final audio file should be as long as the primary file, and if the background music is shorter then it should repeat. If there a Linux command or a Python library that can be used to do this? Sox supports merging, but does not appear to all...

incorrect function being called on multiple fast calls to python's threading.Thread()

I'm having some problems with launching threads from a list of functions. They are in a list because they are configuration-specific functions. I'm wrappering the functions so that I can store the results of the functions in 'self', but something is going wrong in a non-threadsafe way that I get the right number of threads started, but s...

Python print buffering

Let me rephrase my previous question. I just created a tool in ArcGIS using pythong as script language. The tool executes (runs) an outside program using the subprocess.popen. When I run the tool from ArcGSIS, a window appears that only shows the following. Executing: RunFLOW C:\FLOW C:\FLOW\FLW.bat Start Time: Mon Nov 30 16:50:37 2009 ...

Django, updating a user profile with a ModelForm

I'm trying to display a simple ModelForm for a user's profile and allow the user to update it. The problem here is that my logic is somehow flawed, and after a successful form.save() call, the old values show on the page. It isn't until a refresh that the appropriate value is shown. What is wrong here? @login_required def user_profile(r...

Finding the joy of Javascript or searching for another UI-focused languages?

Hey everyone, I'm a GUI designer/interactive musician wanting to improve my programming chops. I already know the basics(variables, loops, arrays, if/else, some logic), but I'm looking to learn in a structured way. I've seen some great books/tuts on Python and Processing (and even Flash)that aim to teach the fundamentals of programming ...

in protocol with regard to sequence

How is this implemented at a python level? I've got an object that pretends to be a dict for the most part (in retrospect I should have just subclassed dict, but I'd rather not refactor the codebase, and I'd also like to know this for future reference), which looks something a bit like class configThinger(object): _config = {} ...