python

Reading corrupted file in python

Hello. I've got a file, that looks like this Now there are 5 lines shown. However running this script with open('hello.txt', 'r') as hello: for line in hello: print line, gives num 1 ctl00$header1$Login1$txtUserName=ыют;CBШ▌ and that's all. How can I read entire file? TIA ...

PyGTK, how can I lock a window so it cannot be resized?

I am looking for a way to lock the window. I found window.set_resizable(False), but that resizes the window to its requested size and then locks it. I would like to be able to resize my window, and then lock it into the size I have resized it to. ...

Having "Exception Value: The _imaging C module is not installed" with my Buildout/Python/Django/PIL on Mac OSX SL?

Hello there. I'm using Buildout for my Django projects, with FeinCMS. I've got it setup great locally on my Mac OSX Snow Leopard, with no errors coming up at all when I use runserver. But when I upload an image with FeinCMS in the admin area it comes up with a "Exception Value: The _imaging C module is not installed" error. My tracebac...

how to generate permutations of array in python?

i have an array of 27 elements,and i don't want to generate all permutations of array (27!) i need 5000 randomly choosed permutations,any tip will be useful... ...

Enabling overriding of app template in django?

I'm writing a simple site to display statistics for some data, and I've got an app called "stats", that I'd like to write default templates for (places in stats/templates/stats), but I'd like these to be overridable in the same way that the templates for the admin app are. IE: If I put a stats/view.html in my project's templates directo...

Python / Linux/ Daemon process trying to show gtk.messagedialog

Hi, on Ubuntu 8/9, i'm trying to write a daemon in python, that monitors a certain network condition and informs the user using a gtk.messagedialog. I installed this script using rc-update. The daemon starts at boot, but doesn't show the dialog even after I login. I assume because init.d starts my daemon at tty1 and no gnome is availabl...

How does Timer in Python work, regarding mutlithreading?

If I call Timer(.1, some_function, [some_arguments]).start() multiple times, what exactly happens behind the scenes? The source of our problem is ... We have a method that's essentially: def move(target): force = calculateForce(target-getCurrentPosition()) if(force != 0) setForce(force) Timer(.1, moveCursor, [tx]).start() ...

pyinstaller: 2 instances of my cherrypy app exe get executed.

I have a cherrypy app that I've made an exe with pyinstaller. now when I run the exe it loads itself twice into memory. Watching the taskmanager shows the first instance load into about 1k, then a second later a second instance of hte exe loads into about 3k ram. If I close the bigger one both processes die. If I close hte smaller one o...

Pretty printing a list of list of floats?

Basically i have to dump a series of temperature readings, into a text file. This is a space delimited list of elements, where each row represents something (i don't know, and it just gets forced into a fortran model, shudder). I am more or less handling it from our groups side, which is extracting those temperature readings and dumping ...

(Py)GTK StatusIcon notifications on Windows

I'm currently writing a screen capture app for Windows and Linux using PyGTK, and I've hit a slight problem with displaying notifications. On Linux, I've been using the libnotify bindings to provide notifications, which has been working very well; however, this has no equivalent on Windows. I'd use the Win32 APIs directly to display the...

iPhone app with Goole App Engine

I've prototyped an iPhone app that uses (internally) sqLite as its data base. The intent was to ultimately have it communicate with a server via PHP, which would use mySQL as the backend database. I just discovered Google App Engine, however, but know very little about it. I think it'd be nice to use the Python interface to write to...

is this a correct ripemd160 core function? (in python)

assuming that everything else (functions, constants, etc) are correct, is this a correct main loop of ripemd160? for j in range(80): T = (a+ ROL( (F(b, c, d, j) + X[r[j]] + k[j/16])%2**32,s[j])+e)%2**32 a = e; e = d; d = ROL(c, 10); c = b; a = T # parallel round T = (aa+ ROL( (F(bb,cc,dd,79-j) + X[rr[j]] + kk[j/16] )%2**32...

Why am I getting dups with random.shuffle in Python?

For a list of 10 ints, there are 10! possible orders or permutations. Why does random.shuffle give duplicates after only 5000 tries? >>> L = range(10) >>> rL = list() >>> for i in range(5000): ... random.shuffle(L) ... rL.append(L[:]) ... >>> rL = [tuple(e) for e in rL] >>> len(set(rL)) 4997 >>> for i,t in enumerate(rL): ... ...

How to return the count of related entities in sqlalchemy query

I'm new to sqlalchemy, and while the documentation seems fairly thorough, I couldn't find a way to do quite what I want. Say I have two tables: forum and post. Each forum has a parent forum, and any number of posts. What I want is: A list of top-level forums Eagerly loaded child forums accessible through the top-level forums A count o...

Unit Conversion in Python

I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both units: http://pypi.python.org/pypi/units/ and quantities: http://pypi.python.org/pypi/quantities/ However I'm not sure the best w...

How can I see error logs of Django views

I'm coding a small application with Django. But I can't see any error logs in the console when an error (e.g. Python syntax error, etc.) occurs in one of my views -no action at all. How can I see the error logs of my views? Debugging like a blind is really annoying. ...

Network IPC With Authentication (in Python)

I am looking for a way to connect a frontend server (running Django) with a backend server. I want to avoid inventing my own protocol on top of a socket, so my plan was to use SimpleHTTPServer + JSON or XML. However, we also require some security (authentication + encryption) for the connection, which isn't quite as simple to implement....

Python: how so fast?

The period of the Mersenne Twister used in the module random is (I am told) 2**19937 - 1. As a binary number, that is 19937 '1's in a row (if I'm not mistaken). Python converts it to decimal pretty darned fast: $ python -m timeit '2**19937' 10000000 loops, best of 3: 0.0271 usec per loop $ python -m timeit -s 'result = 0' 'result += ...

Hudson build failed using Python & Coverage

I completed this tutorial from Joe Heck to set up Hudson for Python. Everything worked perfectly except the Coverage section. My build failed with this output: [workspace] $ /bin/sh -xe /tmp/hudson6222564272447222496.sh + coverage run tests/run.py --with-xunit You must specify at least one of -e, -x, -c, -r, or -a. I tried to includ...

Python property

The output seems a bit fishy given the following code. Why is "get in Base" only printed once? And why is not "set in Base" printed at all? The actual getting/setting seems to work fine though. What am I missing? class Base: def __init__(self): self.s = "BaseStr" def getstr(self): print "get in Base" ret...