python

counting combinations and permutations efficiently

I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers. I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations. So far, I've put in a special case to reflect the symmetry of nCr, but I'd still lik...

How to spawn thread when defined function is set (sequentially dependent) and calling is spatially dependent

Hi. I apologize for my question being a bit confusing. So I have code written in python but also used H3D haptics platform. I'm trying to unload some of the processing of this one, very large thread so that I can log faster. I'm not sure how to write it since a function 'moveCursor' is already defined and later set to a specific number...

Best F/OSS IDE for Python Web Development (Windows or Linux)?

Hi all, Would like to know what is the best F/OSS IDE for Python Web development. I've always used vim myself, but I'm increasingly interested in having a tool that integrates syntax checking/highlighting, source control, debugging, and other IDE goodies. I use both Windows and Linux as desktops, so recommendations for either platform...

How can I iterate over every character in a given encoding using Python?

Is there a way to iterate over every character in a given encoding, and print it's code? Say, UTF8? ...

Parsing name and address information with differing number of spaces

I have a comma delimited text file. The 5th field on each line contains the name and address information. The name is separated from the street information by a '¬' character. The same character also separates the city|state|zip. A sample field would be: "¬BOL¬MICKEY M MOUSE¬123 TOMORROW LANE¬ORLANDO FL 12345-6789¬¬¬¬EOL¬" I need to sep...

Django: What exactly are signals good for?

I have a tough time understanding how signals work into my application (and how they work period). These are three areas where I assume they would apply (with my current knowledge): 1) Send XML to a remote server for reporting (after a transaction is complete). 2) Re size an image and upload the thumbnail to S3 after a user uploads it. ...

Set parent in a ModelForm in Google App Engine

I want to create an Entity Group relationship in an Entity that is being created through a ModelForm. How do I pass the parent instance and set the parent= attribute in the ModelForm? ...

How do I get a µ character out of sqlite and onto a web-page?

On a Python driven web app using a sqlite datastore I had this error: Could not decode to UTF-8 column 'name' with text '300µL-10-10' Reading here it looks like I need to switch my text-factory to str and get bytestrings but when I do this my html output looks like this: 300�L-10-10 I do have my content-type set as: <meta ...

Creating a simple hierarchy structure in Maya using mel/python

So I want to create a very simple structure out of group and locator nodes in Maya which will then be exported for use in my game level. e.g. Group_Root group_parent - group1 - locator1 - group2 - locator2 - group3 There is only one Group_Root in the file, there are many group_parents ( each uniquely named ...

how to safely generate a SQL LIKE statement using python db-api

I am trying to assemble the following SQL statement using python's db-api: SELECT x FROM myTable WHERE x LIKE 'BEGINNING_OF_STRING%'; where BEGINNING_OF_STRING should be a python var to be safely filled in through the DB-API. I tried beginningOfString = 'abc' cursor.execute('SELECT x FROM myTable WHERE x LIKE '%s%', beginningOfStrin...

Pylons and multiple forms per page

Hi all, I've got a web page I'm generating with Pylons and the evoque templating tool. I'm trying to generate a page with multiple forms per page (one form is part of a base template that becomes part of every page). I'm having a problem as I seemingly can only get the form element values for one form; whenever I try to get the value fr...

Easy way to get data between tags of xml or html files in python?

I am using Python and need to find and retrieve all character data between tags: <tag>I need this stuff</tag> I then want to output the found data to another file. I am just looking for a very easy and efficient way to do this. If you can post a quick code snippet to portray the ease of use. Because I am having a bit of trouble u...

can SimpleXMLRPCServer listen on multiple addresses?

I have two IPs mapping to the machine, and I was wondering how I can have one python xmlrpc server listening on both IPs (same port), like you could do with Apache. Thank you, ...

Should I create each class in its own .py file?

I'm quite new to Python in general. I'm aware that I can create multiple classes in the same .py file, but I'm wondering if I should create each class in its own .py file. In C# for instance, I would have a class that handles all Database interactions. Then another class that had the business rules. Is this the case in Python? ...

Using a function to create a function in Python

Hi, I'm new to programming and I'm interested in if it's possible to use a function to create another function based in inputted information: def get_new_toy(self): new_toy = gui.multenterbox( msg = 'Enter the data for the new toy:', title = 'New Toy', fields = ('Toy Name', 'Fun for 0 to 5', 'Fun for 5 to 7'...

What is the purpose of pinax's groups?

I viewed the DjangoCon 2009 talks about pinax by James Tauber and pydanny and heared about pinax's groups. But I don't get the actual usecases they describe, even after reading the documentation. So what is the real purpose of groups and what advantages do I get in using them? It would be nice if you could provide a simple usecase to l...

Python optparse not seeing argument.

I am trying to pass '-f nameoffile' to the program when I call it from the command line. I got this from the python sites documentation but when I pass '-f filename' or '--file=filename' it throws the error that I didnt pass enough arguments. If i pass -h the programs responds how it should and gives me the help. Any ideas? I imagine ...

Python Detect Keystrokes Sent to Another Application

I have a Python program that sends keystrokes to another application using SendKeys. Some of the keystrokes, however, must be sent to the application after it does some processing (which takes an unknown amount of time). So far I have had to let the Python application know the processing was finished by Alt+Tabbing back to the DOS window...

GAE datastore eager loading in python api

I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model): answerText = db.StringProperty(multiline=False) question = db.ReferenceProperty(Question, collection_name='answers') I have front-end implemented in F...

Python Send Keystrokes to Non-Active Application

I'm automating some common GUI tasks I have to do in an application, and I'm using a Python program and SendKeys to do it. So far I've had to activate the application I'm sending keys to (since SendKeys just sends the keystrokes to the active window), but I'd like to be able to send keystrokes to an application in the background. Is ther...