python

pixelwise drawing in pyglet (python)

OK. I'm tired of googling and reading throught lots of documentation with no results. My aim is simple: get pyglet to draw an image pixel by pixel. I've been searching for hours with no results. Can anyone give an example of a short program that draws in a display specifying the color pixel by pixel? (for example, drawing a gradient fro...

Move an email in GMail with Python and imaplib

I want to be able to move an email in GMail from the inbox to another folder using Python. I am using imaplib and can't figure out how to do it. ...

Django debugging with Eclipse and PyDev

Hi, I just managed to get debugging my django site 'kind of' working in Eclipse. All my breakpoints get caught just fine, but I have to restart the server every time I make a code change. I think this is because I'm using the --noreload argument when kicking off the server. Is there any way to setup Eclipse debugging so that I can chan...

search and replace text inline in file in Python

I am trying to convert a file which contains ip address in the traditional format to a file which contains ip address in the binary format. the file contents are as follows. src-ip{ 192.168.64.54 } dst-ip{ 192.168.43.87 } The code i have is as follows. import re from decimal import * filter = open("filter.txt", "r") output = open...

How to generate a UUID of type long (to be consumed by a java program) in Python?

How do you generate UUID of type long (64 bits - to be consumed by a java program) using Python? I read about the UUID module. So I played with it a bit: >>> import uuid >>> uuid.uuid1().int 315596929882403038588122750660996915734L Why is there an "L" at the end of the integer generated by uuid.uuid1().int? If it's an integer should...

Convert decimal to binary in python

Hello, Is there any module or function in python i can use to convert a decimal number to its binary equivalent ? I am able to convert binary to decimal using int('[binary_value]',2),so any way to do the reverse without writing the code to do it myself ? Thank You ...

Using Microsoft SQL through python on a webserver

I'm trying to run some queries to a database from a pylons (paster-based) webserver and every time I try to import the pymssql Library I'm using (its this one by the way) I keep getting this error: tds_init_winsock: WSAEnumProtocols failed with 10055(WSAENOBUFS: No buffer space available.) on the import. I also tried using sqlalchemy ...

Why do Python programmers still use old-style division?

I started using Python in 2001. I loved the simplicity of the language, but one feature that annoyed the heck out of me was the / operator, which would bite me in subtle places like def mean(seq): """ Return the arithmetic mean of a list (unless it just happens to contain all ints) """ return sum(seq) / len(seq) F...

How to create MUC and send messages to existing MUC using Python and XMPP

I was wondering if anyone here can provide some code samples on the following scenarios. I'm particularly interested in using xmpppy to do this as I'm already using the library for my app, but other libraries ok too. It is unfortunate that the xmpppy project website doesn't have any samples on this. Browsing the expert/advanced API docs,...

Jython: Access singleton Java class (static)

Hi, I cannot seem to get the syntax quite right for this: I have a Jython script and a Java application loaded into the same JVM (for testing). I need to access a particular part of the application through a Singleton class from the Jython script. How do I do this? Thanks EDIT: The set up is for automated testing, so assume that t...

pyglet silent exit with multiprocessing?

Pyglet exits unexpectedly and silently if I do this: from multiprocessing import Process import pyglet from pyglet.gl import * def myProcess(): w = pyglet.window.Window() pyglet.app.run() p = Process(target = myProcess) p.start() while p.is_alive(): pass It works as expected (opens an empty window and sits there) if I ch...

Replace a pattern in python

How to replace the pattern in the string with decoded_str=" Name(++info++)Age(++info++)Adress of the emp(++info++)" The first pattern "(++info++)" needs to replaced with (++info a++) The second pattern "(++info++)" needs to replaced with (++info b++) The third pattern "(++info++)" needs to replaced with (++info c++) If there m...

Python regex, how-to group an item within a regex

Hi all, I'm having trouble creating a regex. Here is a sample of the text on which the regex should work: <b>Additional Equipment Items</b> <br> 40001 <br> 1 Battery Marathon L (8 cells type L6V110) <br> 40002 <br> What I now want to select is >>1<< and >>Battery Marathon L (8 cells type L6V110)<<. Therefore I have produced the...

py2exe: Reduce size of the library archive

Hi. I just created my first py2exe executable and noticed that with the EXE, there is a ZIP file created with the size of around 1.4 MB. My question is, can I reduce the size of this or is it expected that the typical size of an EXE generated with py2exe will be ~ 4 MB (that means with all the files: python2.6dll, library.zip) ...

Django ORM Query: relationships

There is a model: class DomainPosition(models.Model): domain = models.ForeignKey(Domain) keyword = models.ForeignKey(Keyword) date = models.DateField() position = models.IntegerField() class Meta: ordering = ['domain', 'keyword'] How to get the data for a template? For each domain want to display table (fi...

Capture Image as Array with Python OpenCV

I've seen from the sample how to display an image from the webcam, but how do I get the image captured as an array? import cv capture = cv.CaptureFromCAM(0) img = cv.QueryFrame(capture) img.tostring() gives me weird caracters. Thanks in adv. ...

How to receive and parse a HTTP incoming request using python?

How to receive and parse a HTTP incoming request using python? ...

Create frame class in Tkinter Gui.

Hello, I'm working on a Gui and I'd like to know how to create a class that would implement frame. e.g. class WindowContent(Tkinter.?) """ This class would create a frame for my program window """ class App(Tkinter.Tk): """ main window constructor """ def __init__(self): Tkinter.Tk.__init__(self) program...

Question for join

Hello Folks, I have no clue about python and started to use it on some files. I managed to find out how to do all the things that I need except for 2 things. Ipadd = string.join (line['0,1,2,4,5,6']) does not work if I make it (line[0:2]) It prints out the first two fields and thats good so far but I need field 4 and 6 also. but (line[0...

setting up the environment when changing to another user

I have a bash backup script run as root (cron) that delegates certain tasks to other specific bash scripts owned by different users. (simplified example, principle is, some things have to be done as root, different tasks are delegated to users with the appropriate environment (oracle, amazon, ...) mkdir -p /tmp/backup$NAME su - oracle -...