python

Why am I getting a little-endian error when importing .so file in python.

Im attempting to use a C++ extension for Python called PySndObj. and getting an error I have never seen and cannot find anything about on the web :( ImportError: /home/nhnifong/SndObj-2.6.6/python/_sndobj.so: ELF file data encoding not little-endian I know that probably means the byte order is backwards, So I tried writing a little scr...

Deleting from dict if found in new list in Python

Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value? E.g: dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5} How do I do this without creating a new ...

PHPs call_user_func_array in Python

Is there an equivilant in Python for PHPs call_user_func_array? ...

python or bash - adding " at beginning of line and ", at end of line

I have text file with something like first line line nr 2 line three etc And i want to generate "first line", "line nr 2", "line three", I wonder how to do this in python or maybe in bash if it's easier/quicker. I know there is different code for opening file and different for reading only one line in python(?) but i'm not sure wh...

How do you call PyObjC code from Objective-C?

I'm a long-time Python programmer and short-time Cocoa programmer. I'm just getting started with PyObjC and it's really amazing how easy it it is to get stuff done. That said, I wanted to try using pure ObjC for my controller with PyObjC models. I might be enjoy letting Python be Python and Objective-C be Objective-C. I figured it was wo...

Run python script without DOS shell appearing

Is there any way to run a python script in Windows XP without a command shell momentarily appearing? I often need to automate word perfect (for work) with python, and even if my script has no output, if I execute it from without WP an empty shell still pops up for a second before disappearing. Is ther any way to prevent this? Some kind o...

Overhead of a Round-trip to MySql?

So I've been building django applications for a while now, and drinking the cool-aid and all: only using the ORM and never writing custom SQL. The main page of the site (the primary interface where users will spend 80% - 90% of their time) was getting slow once you have a large amount of user specific content (ie photos, friends, other ...

Is there a more succinct / pythonic way to do this? (counting longest seq of heads, tails in coin flips)

Count the longest sequence of heads and tails in 200 coin flips. I did this - is there a niftier way to do it in python? (without being too obfuscated) import random def toss(n): count = [0,0] longest = [0,0] for i in xrange(n): coinface = random.randrange(2) count[coinface] += 1 count[not coinface]...

Are there any alternatives to py2exe?

Are there any alternatives to py2exe? ...

handling multiple returned objects

I have a contact/address app that allows users to search the database for contact entries. The current view will return an object (Entry()) and display its fields. The code is as follows: def search_page(request): form = SearchForm() entrylinks = [] show_results = True if request.GET.has_key('query'): show_resu...

What can cause select to block in Python?

Here's a snippet of code I'm using in a loop: while True: print 'loop' rlist, wlist, xlist = select.select(readers, [], [], TIMEOUT) print 'selected' # do stuff At a certain point, select will block and "selected" is never getting printed. What can cause this behavior? Is it possible there's some kind of deadlock? U...

Python: ulimit and nice for subprocess.call / subprocess.popen ?

I need to limit the amount of time and cpu taken by external command line apps I spawn from a python process using subprocess.call , mainly because sometimes the spawned process gets stuck and pins the cpu at 99%. nice and ulimit seem like reasonable ways to do this, but I'm not sure how they'd interact with subprocess. The limits lo...

Tool like 2to3, except for merges

I maintain a fork of my project for Python 3.1. When I initially made the port from 2.6, I used 2to3, but now I constantly have to merge new code from the 2.6 fork into the 3.1 fork. How can I perform the 2to3 operation on these merges automatically? (I use git, if it matters.) ...

How do I upload data to Google App Engine periodically?

I'm writing an aggregation application which scrapes data from a couple of web sources and displays that data with a novel interface. The sites from which I'm scraping update every couple of minutes, and I want to make sure the data on my aggregator is up-to-date. What's the best way to periodically submit fresh data to my App Engine ap...

In Python 2.6.4, why do I get a syntax error for a function call, of which the function is defined and works perfectly on its own?

This happens in IDLE and Windows 7 RC1 (if that helps). Here is the module: from math import * from TurtleWorld import * world = TurtleWorld() bob = Turtle() bob.delay = 0.1 def polyline(turtle, length, n, angle): for i in range(n): fd(turtle, length) rt(turtle, angle) def polygon(turtle, length, n): """ p...

Sending a retrieved SMS using Python

Hi Guys, I am writing a Python script to read a SMS from the SIM memory, buffer it and send the same SMS to another number. I am executing this script on Telit GM862-GPS. The script I have written is : import MDM MDM.send('AT+CMGF=1\r', 10) # Changing to Text mode MDM.send('AT+CMGR=1\r',0) # ...

Browser Detection Python / mod_python?

I want to keep some statistics about users and locations in a database. For instance, I would like to store "Mozilla","Firefox","Safari","Chrome","IE", etc... as well as the versions, and possibly the operating system. What I am trying to locate from Python is this string; Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.14) Gecko/200...

Modulus in Python's slicing

How can you fix the following code? I want to get the slice of elements that are i mod 5 == 1. data = "8|9|8|9|8|9|8|9|9|8|9|8|9|8|9|8" arra = map(int,data.split("|")) sums += [sum(arra[i % 5==1:(i + 4) % 5==1]) // Problem here for i in range(0, len(arra), 4)] ...

What technologies are good for sending encapsulated data, and later converting it, between Python and Objective-C?

Hello! I'm attempting to create a client/server web-app. The client software is written in Objective-C (Mac), and the server software is written in Python (Linux). I'd like to encapsulate object data on either side, and send it across the internet to the other side. This will include standard types such as strings, doubles, and data-...

AND in Python's slicing with modulus

How can you fix the code? I am trying to have i % 3 == 1 and i != 16 unsuccessfully by data = "8|9|8|9|8|9|8|9|9|8|9|8|9|8|9|8" arra = map(int,data.split("|")) arra = sum(arra[1::3 and != 16]) for i in range(0, len(arra), 16)] | |---// Problem here ...