Skip to main content.
July 8th, 2008

Fixing RDO Error (Exchange) When Trying to Move an Email

I’m using Python win32 stuff to automate some Exchange tasks. This is an issue I ran into.

Here’s my one-way email correspondence with the authors that lists the error and how I fixed it:

This turned out to be a permissions issue. Sorry for the bother.

-Greg

—–Original Message—–
From: Greg Pinero
Sent: Tuesday, July 08, 2008 11:02 AM
To: redemption@di….com
Subject: Outlook Redemption Question

Hi there,

I’m trying to use the RDOMail object’s Move method:

Move(DestFolder)
Moves message to a new folder.
DestFolder - The destination folder (RDOFolder object).
Returns the new message (RDOMail object) in the destination folder.

However I am getting this error:

Traceback (most recent call last):
File ““, line 1, in ?
File “>”, line 2, in Move
com_error: (-2147352567, ‘Exception occurred.’, (0, ‘Redemption.RDOMail’, ‘Error in IMAPITable.FindRow(PR_SEARCH_KEY): MAPI_E_NOT_FOUND’, None, 0, -2147221233), None)

I’m simply calling e.Move(rdoFolder)

Where e is an email message and rdoFolder is an RDO folder of the folder I want to move the message to. Let me know if it would help to see my code.

Thanks in advance for the help.

Greg Pinero

Posted by Greg Pinero (Primary Searcher) as win32, Python, Other at 11:26 AM MST

No Comments »

June 26th, 2008

Python - How to Make MySQLdb Store Query Results on the Server

Sometimes I’ll want to run a query against a MySQL database from Python that returns a large result set. So large in fact that Python hits a memory error.

One way around this is to have the Python MySQL library (MySQLdb) store the results from a query on the database server and bring them back to you one at a time as you request them.

Here’s how you set that up:

import MySQLdb
import MySQLdb.cursors #Make sure to import this seperately

#build your connection object normally but pass it a cursorclass keyword
db=MySQLdb.connect(host=HOSTNAME,user=USERNAME,passwd=PASSWORD,db=DATABASE,
            cursorclass=MySQLdb.cursors.SSCursor)

#Usage

cursor=db.cursor()
cursor.execute('select huge_column from huge_table')
#iterate over the results pulling them down from the server on each iteration
for row in cursor:
    print row
cursor.close()

Posted by Greg Pinero (Primary Searcher) as Python at 8:49 PM MST

1 Comment »

March 26th, 2008

Python - Fixing SyntaxError: ‘return’ with argument inside generator

This error is telling you that when you use a yield inside of a function making it a generator, you can only use return with no arguments.

This makes sense because return raises a StopIteration error in a generator and it would be quite unexpected to be getting values back with that.

Here is how you can accomplish what you need to do though:

Say you want to do this:

def f():
    for i in range(2):
        yield i
    return i+2

You can do this instead and probably get a result close enough to what you want:

def f():
    for i in range(2):
        yield i
    yield i+2
    return

Posted by Greg Pinero (Primary Searcher) as Python at 9:02 AM MST

2 Comments »

February 22nd, 2008

Two Dimensional Discrete Cosine Transform (DCT-II) in Python

Here’s my first shot at implementing the 2D discrete cosine transform in Python. It seems to work, but let me know in the comments if it’s wrong, or if you know of any easy ways to speed it up.

import numpy
#shortcuts
from numpy import pi
from math import cos,sqrt

def two_dim_DCT(X):
    """2D Discrete Cosine Transform
    X should be square 2 dimensional array
    Trying to follow:
    http://en.wikipedia.org/wiki/Discrete_cosine_transform#Multidimensional_DCTs
    http://en.wikipedia.org/wiki/JPEG#Discrete_cosine_transform"""
    result=numpy.zeros(X.shape)
    N1,N2=X.shape
    def alpha(n):
        """Normalizing function, not sure if necessary"""
        if n==0:return 0.353553390593 #sqrt(1/8.)
        else:return .5 #sqrt(2/8.)
    for (k1,k2),_ in numpy.ndenumerate(X):
        sub_result=0.
        for n1 in range(N1):
            for n2 in range(N2):
                sub_result+=X[n1,n2] * cos((pi/N1)*(n1+.5)*k1)*cos((pi/N2)*(n2+.5)*k2)
        result[k1,k2]=alpha(k1)*alpha(k2)*sub_result
    return result

Posted by Greg Pinero (Primary Searcher) as Python at 9:24 PM MST

4 Comments »

February 19th, 2008

How do I Find What Version of PIL I have?

In your Python session:

from PIL import Image
print Image.VERSION

Posted by Greg Pinero (Primary Searcher) as Python at 11:08 PM MST

Comments Off

« Previous Entries