python

What does python3 do with the methods passed to the "key" argument of sorted()?

I have a question about how python treats the methods passed to sorted(). Consider the following small script: #!/usr/bin/env python3 import random class SortClass: def __init__(self): self.x = random.choice(range(10)) self.y = random.choice(range(10)) def getX(self): return self.x def getY(self): ...

Django Custom Template Tags In Google App Engine

I am trying to include the following Tag In Google App Engine Web Application: http://www.djangosnippets.org/snippets/1357/ Is there any configuration of this file to make it work with Google App Engine? Cause I followed the Django Template tutorials: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/ and have this stru...

Installing Django on Shared Server: No module named MySQLdb?

I'm getting this error Traceback (most recent call last): File "/home/<username>/flup/server/fcgi_base.py", line 558, in run File "/home/<username>/flup/server/fcgi_base.py", line 1116, in handler File "/home/<username>/python/django/django/core/handlers/wsgi.py", line 241, in __call__ response = self.get_response(request) F...

Python $OUTPUT_RECORD_SEPARATOR and $INPUT_RECORD_SEPARATOR equivalent

Does Python have an equivalent to the $OUTPUT_RECORD_SEPARATOR or $\ in Perl? UPDATE: I totally had this wrong... I was looking for a Python equivalent to a $INPUT_RECORD_SEPARATOR if there is such a thing? Something that you can override so that when you do a readline() type call its looking for something other than the newline char. S...

(Python) socket.gaierror: [Errno 11001] getaddrinfo failed

I'm not sure whats wrong with this code I keep getting that socket.gaierror error ;\ . import sys import socket import random filename = "whoiservers.txt" server_name = random.choice(list(open(filename))) print "connecting to %s..." % server_name s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((server_name, 43)) s.se...

GStrings in Python

Groovy has a concept of GStrings. I can write code like this: def greeting = 'Hello World' println """This is my first program ${greeting}""" I can access the value of a variable from within the String. How can I do this in Python? -- Thanks ...

Python + PHP + Lighttpd?

I've set up a few web servers in my day, but I'm not sure how they work internally. I'm setting up a new environment for myself and I'm interested in configuring my lighttpd server to support both PHP and Python. Is this possible? ...

Monitoring a tcp port

For fun, I've been toying around with writing a load balancer in python and have been trying to figure the best (correct?) way to test if a port is available and the remote host is still there. I'm finding that, once connected, it becomes difficult to tell when the remote host goes down. I've turned keep alive on, but can't get it to r...

Call python script from AIR application?

How can we invoke a python script using AIR 1.5? ...

What does the 'shell' argument in subprocess mean on Windows?

The docs for the subprocess module state that 'If shell is True, the specified command will be executed through the shell'. What does this mean in practice, on a Windows OS? ...

Python: how to store a draft email with BCC recipients to Exchange Server via IMAP?

I try to store a draft e-mail via IMAP to a folder running on MS Exchange. Everything ok, except that Bcc recipients don't get shown in the draft message stored on the server. Bcc recipients also don't receive the email if I send it with MS Outlook. If I read the message back with Python after I have stored it on the server, I can see th...

pyqt4 and pyserial

I want to do an app constantly watching the serial port and changing the user interface according to the input received from the port. I've managed to read lines from the port with pyserial under Linux, but I'm not sure how to do this in a regular fashion: create a separate thread and check for input on a timer event? How do i make sure ...

How to add a second bouncing ball to the window?

I have coded an animation (in python) for a beach ball to bounce around a screen. I now wish to add a second ball to the window, and when the two collide for them to bounce off each other. So far, my attempts at this have been unsuccessful. Any ideas how to do this? The code I have so far is below. import pygame import sys if __nam...

Running python code from standard Cocoa application

I have an XCode project built as a Cocoa single document application (it's not a Python-Cocoa application, that is not what I want). All the documentation I found assumes I want to create a Cocoa application with code written in Python and this is not the case - I want a standard Cocoa application that calls a method out of a Python cla...

What does the Python Ellipsis object do?

While idly surfing the namespace I noticed an odd looking object called "Ellipsis", it does not seem to be or do anything special, but it's a globally available builtin. After a search I found that it is used in some obscure variant of the slicing syntax by Numpy and Scipy... but almost nothing else. Was this object added to the lang...

Django payment proccessing

Can anyone suggest any good payment processing libraries for python/django? ...

Oracle / Python Converting to string -> HEX (for RAW column) -> varchar2

I have a table with a RAW column for holding an encrypted string. I have the PL/SQL code for encrypting from plain text into this field. I wish to create a trigger containg the encryption code. I wish to 'misuse' the RAW field to pass the plain text into the trigger. (I can't modify the schema, for example to add another column for th...

How to create a password protected zipfile with python ?

Since python2.6, it's now easier to extract data from a password protected zip. But how to create a password protected zipfile in pure python ? ...

Free word list for use programatically?

A friend of mine was talking about a word game she liked to play where you try to convert one word to another (they have the same number of letters) by switching one letter at a time, where each iteration produces a real word. Example: MOON --> WOLF GOON GOOF GOLF WOLF I figured it'd be a fun little project to write a prog...

Why are 0d arrays in Numpy not considered scalar?

Surely a 0d array is scalar, but Numpy does not seem to think so... am I missing something or am I just misunderstanding the concept? >>> foo = numpy.array(1.11111111111, numpy.float64) >>> numpy.ndim(foo) 0 >>> numpy.isscalar(foo) False >>> foo.item() 1.11111111111 ...