python

Cleaning up an internal pysqlite connection on object destruction

I have an object with an internal database connection that's active throughout its lifetime. At the end of the program's run, the connection has to be committed and closed. So far I've used an explicit close method, but this is somewhat cumbersome, especially when exceptions can happen in the calling code. I'm considering using the __de...

python not starting properly

I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run properly? ...

Multiply operator applied to list(data structure)

Hello there I'm reading How to think like a computer scientist which is an introductory text for "Python Programming". I want to clarify the behaviour of multiply operator (*) when applied to lists. Consider the function make_matrix def make_matrix(rows, columns): """ >>> make_matrix(4, 2) [[0, 0], [0, 0], [0, 0], [0, 0]] >>> m...

Python: splitting an integer into digits

I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a basic exercise I am no...

access is denied in GAE in eclipse

When I am trying to to do Model.put() in eclipse for a google python app after changing the parameter of --datastore_path="F:/tmp/myapp_datastore" in arguments of debug configurations.I dont know if its related to above change or is there any other magic behind the scene. Any help. exception value:[Error 5] Access is denied UPDATE, A...

Sending email using google apps SMTP server in Python 2.4

I'm having difficulty getting python 2.4 to connect to gmail's smtp server. My below script doesn't ever get past "connection". I realise there is an SMTP_SSL class in later versions of python and it seems to work fine, but the production environment I have to deal with only has - and likely will only ever have - python 2.4. print "conn...

redirecting sys.stdout to python logging

Hi, So right now we have a lot of python scripts and we are trying to consolidate them and fix and redundancies. One of the things we are trying to do, is to ensure that all sys.stdout/sys.stderr goes into the python logging module. Now the main thing is, we want the following printed out: [<ERROR LEVEL>] | <TIME> | <WHERE> | <MSG> ...

Why is Logging going in an infinite Loop?

I have the following code: #!/usr/bin/env python import logging import sys import copy class Wrapper: def write(self, s): #sys.__stdout__.write(s) loggy = logging.getLogger('foobar') loggy.info(s) def blah(): logger = logging.getLogger('foobar') logger.setLevel(logging.DEBUG) streamhandle = logg...

connection reset for concurrent usage by two users GAE

I am trying to access same python web app in GAE from firefox and IE with different user login and when I start the IE session I get the following error with IE going standstill. why? error: (10054, 'Connection reset by peer') ...

Perl and CopSSH

I'm trying to automate a process on a remote machine using a python script. The machine is a windows machine and I've installed CopSSH on it in order to SSH into it to run commands. I'm having trouble getting perl scripts to run from the CopSSH terminal. I get a command not found error. Is there a special way that I have to have perl ins...

Can Python adodbapi be used to connect to a paradox db?

Can Python adodbapi be used to connect to a paradox db? If yes what would the connection string look like? ...

Best way to get the name of a button that called an event?

In the following code (inspired by this snippet), I use a single event handler buttonClick to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to add 50 buttons instead of 2, this method could become cumbersome. Is there a better way to do this? import ...

Problem with Python interpreter in Eclipse

When trying to set the interpreter for python in Eclipse by choosing the executable, clicking OK displays "An error has occured." Does the interpreter name matter? ...

Random hash in Python

What is the easiest way to generate a random hash (MD5) in Python? ...

python-scapy: how to translate port numbers to service names?

A TCP layer in Scapy contains source port: >>> a[TCP].sport 80 Is there a simple way to convert port number to service name? I've seen Scapy has TCP_SERVICES and UDP_SERVICES to translate port number, but print TCP_SERVICES[80] # fails print TCP_SERVICES['80'] # fails print TCP_SERVICES.__getitem__(80) # fails print TCP_SERVICES['ww...

Thinking in AppEngine

I'm looking for resources to help migrate my design skills from traditional RDBMS data store over to AppEngine DataStore (ie: 'Soft Schema' style). I've seen several presentations and all touch on the the overarching themes and some specific techniques. I'm wondering if there's a place we could pool knowledge from experience ("from the...

Python web frameworks, an honest opinion required.

Possible Duplicates: Recommendation for straight-forward python frameworks Python Webframework Confusion I am starting two projects for my company that will eventually become linked together. The first is an in-house reservations and management system for arranging exhibitions and conferences for delegates and the second a web...

Can I make Python 2.5 exit on ctrl-D in Windows instead of ctrl-Z?

I'm used to ending the python interactive interpreter using Ctrl-d using Linux and OS X. On windows though, you have to use Ctrl-z and then enter. Is there any way to use Ctrl-d? ...

Shuffling a list of objects in python

I have a list of objects in python and I want to shuffle them. I thought I could use the random.shuffle method, but this seems to fail when the list is of objects. Is there a method for shuffling object or another way around this? import random class a: foo = "bar" a1 = a() a2 = a() b = [a1,a2] print random.shuffle(b) This will...

static stylesheets gets reloaded with each post request

Every time there is a post from page the entire bunch of css gets reloaded. Is it possible to tell them not to come in again and again. There is a series of GET that get fired. Can we optimize in some way or is it normal behavior? The environment is google apps in python. ...