python

Django ManyToMany Template Questions

Good Morning All, I've been a PHP programmer for quite some time, but I've felt the need to move more towards the Python direction and what's better than playing around with Django. While in the process, I'm come to a stopping point where I know there is an easy solution, but I'm just missing it - How do I display manytomany relationsh...

PyQt : why adding a dummy class definition in my file make the application crash?

Consider the code below: #!/usr/bin/env python from PyQt4 import QtCore, QtGui import os,sys class MainWindow(QtGui.QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.listWidget = QtGui.QListWidget(None) self.setCentralWidget(self.listWidget) if __name__ == ...

python sub-process

Hi, i am beginner in python I am trying to run a " FORTRAN file from python using subprocess " I wrote a python program: import string import subprocess as subProc from subprocess import Popen as ProcOpen from subprocess import PIPE import numpy import subprocess userID = "pear" serverName = "say4" workDir = "/home/pear/2/W/fortran/"...

PIL does not save transparency

from PIL import Image img = Image.open('1.png') img.save('2.png') The first image has a transparent background, but when I save it, the transparency is gone (background is white) What am I doing wrong? ...

How long do zipimported module imports remain cached in memory when using appengine / python and is there a way to keep them in memory?

I've recently uploaded an app that uses django appengine patch and currently have a cron job that runs every two minutes. On each invocation of the worker url it consumes quite a bit of resources /worker_url 200 7633ms 34275cpu_ms 28116api_ms That is because on each invocation it does a cold zipimport of all the libraries django etc...

In GTK, how do I get the actual size of a widget on screen?

First I looked at the get_size_request method. The docs there end with: To get the size a widget will actually use, call the size_request() instead of this method. I look at size_request(), and it ends with Also remember that the size request is not necessarily the size a widget will actually be allocated. So, is there any f...

In Twisted Python - Make sure a protocol instance would be completely deallocated

Hey, I have a pretty intensive chat socket server written in Twisted Python, I start it using internet.TCPServer with a factory and that factory references to a protocol object that handles all communications with the client. How should I make sure a protocol instance completely destroys itself once a client has disconnected? I've got...

Introspecting a given function's nested (local) functions in Python

Given the function def f(): x, y = 1, 2 def get(): print 'get' def post(): print 'post' is there a way for me to access its local get() and post() functions in a way that I can call them? I'm looking for a function that will work like so with the function f() defined above: >>> get, post = get_local_func...

How to roll my own pypi?

I would like to run my own internal pypi server, for egg distribution within my organization. I have found a few projects, such as: http://pypi.python.org/pypi/EggBasket/ http://plone.org/products/plonesoftwarecenter As I understand it, pypi.python.org uses software called Cheese Shop. My questions: Why can't I use cheeseshop ...

Python: how can I handle any unhandled exception in an alternative way?

Normally unhandled exceptions go to the stdout (or stderr?), I am building an app where I want to pass this info to the GUI before shutting down and display it to the user and, at the same time I want to write it to a log file. So, I need an str with the full text of the exception. How can I do this? ...

In GTK, how do I make a window unable to be closed?

Example: graying out the "X" on windows systems. ...

Searching a Unicode file using Python

Setup I'm writing a script to process and annotate build logs from Visual Studio. The build logs are HTML, and from what I can tell, Unicode (UTF-16?) as well. Here's a snippet from one of the files: c:\anonyfolder\anonyfile.c(17169) : warning C4701: potentially uninitialized local variable 'object_adrs2' used c:\anonyfolder...

Comparing persistent storage solutions in python

I'm starting on a new scientific project which has a lot of data (millions of entries) I'd like to store in an easily and quickly accessible format. I've come across a number of different potential options, but I'm not sure how to pick amongst them. My data can probably just be stored as a dictionary, or potentially a dictionary of dicti...

Python: remove dictionary from list

If I have a list of dictionaries, say: [{'id': 1, 'name': 'paul'}, {'id': 2, 'name': 'john'}] and I would like to remove the dictionary with id of 2 (or name john), what is the most efficient way to go about this programmatically (that is to say, I don't know the index of the entry in the list so it can't simply be popped). ...

Execute python code inside browser without Jython

Is there a way to execute python code in a browser, other than using Jython and an applet? The execution does not have to deal with anything related to graphics. For example, just sum all the digits of a binary 1Gb file (chosen by the browser user) and then return the result to the server. I am aware that python can be executed remotel...

new django app's from 1.1 causing 500 error

i'm running on wsgi on centos 5... i've recently updated locally from 1.0 to 1.1 I updated the server using svn update now when I apply a new app developed locally to the server it returns with a 500 error. all i'm doing is python manage.py startapp appname adding the app into installed_apps in the settings file and uploading thi...

Using localflavor Django form fields on Google's App Engine

Is it possible to use the form fields from django.contrib.localflavor.us.forms on the Google App Engine? Can I simply use those form fields, or do I need a form field under google.appengine.ext.db.djangoforms ...

wxPython gauge problem (skipping)

Pastebin link: http://pastebin.com/f40ae1bcf The problem: I made a wx.Gauge, with the range of 50. Then a function that updates Gauge's value when the program is idle. When the gauge is filled by around 50% it empties and doesn't show anything for a while. The value is actually 50 when it does this, and I think that when the value is 50...

Compiling python modules whith DEBUG defined on MSVC

Python rather stupidly has a pragma directive in its include files that forces a link against python26_d.lib when the DEBUG preprocessor variable is defined. This is a problem because the python installer doesn't come with python26_d.lib! So I can't build applications in msvc in debug mode. If i temporarily #undef DEBUG for just one file...

py2app error: "can't copy '%s': doesn't exist or not a regular file"

I'm trying to pack my Python app with py2app. I'm running the setup.py I created, and I get this error: File "C:\Python26\lib\distutils\file_util.py", line 119, in copy_file "can't copy '%s': doesn't exist or not a regular file" % src DistutilsFileError: can't copy '--dist-dir': doesn't exist or not a regular file > c:\python26\l...