ctypes NULL pointers; was: Python To Send Emails Via Outlook Express

2005-01-02 Thread Lenard Lindstrom
his clears up any confusion my Simple MAPI example may have caused regarding ctypes pointers. Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Subclassed dict as globals

2005-01-26 Thread Lenard Lindstrom
glbs = dict(globals()) >>> for id in cd.co_names: glbs[id] = 'K' + id >>> exec cd in glbs Kx Ky Kz Special names can be used only as constants. It is better suited for eval() than exec. Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python mascot proposal

2004-12-13 Thread Lenard Lindstrom
Steven Bethard <[EMAIL PROTECTED]> writes: > Brian Beck wrote: > > http://exogen.cwru.edu/python2.png > > Oooh, I like this one. Very cool! > Its visually stunning. But under Windows gears show up in the DLL and batch file icons. Lenard Lindstrom <[EMAIL PROTECTED]&

Re: Python mascot proposal

2004-12-13 Thread Lenard Lindstrom
now I don't care any more whether you use a Python, some other snake, a foot or 16-ton weight, or a wood rat as a logo for Python! Of course any official logo would likely require a PEP and the BDFL's endorcement. But before that it might be an idea to see if it becomes popular as a de

Re: Adding paths to sys.path permanently, and another problem...

2004-12-16 Thread Lenard Lindstrom
sistence I can try writing an example that does it automatically using the atexit module and a history file. Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python mascot proposal

2004-12-14 Thread Lenard Lindstrom
Steven Bethard <[EMAIL PROTECTED]> writes: > Lenard Lindstrom wrote: > > Steven Bethard <[EMAIL PROTECTED]> writes: > > > >>Brian Beck wrote: > >> > >>>http://exogen.cwru.edu/python2.png > >> > >>Oooh, I like this one. Ve

Re: Python To Send Emails Via Outlook Express

2004-12-21 Thread Lenard Lindstrom
. I have also not tried using Simple Mapi under Python, only VC++. But a quick test shows I can access MAPI32.DLL use the ctypes package: import ctypes mapi = ctypes.windll.mapi32 MAPILogon = mapi.MAPILogon ... It is messy though. Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python To Send Emails Via Outlook Express

2004-12-21 Thread Lenard Lindstrom
byref(msg), 0, 0) if rc != SUCCESS_SUCCESS: raise WindowsError, "MAPI error %i" % rc = Example usage = import SimpleMAPI SimpleMAPI.SendMail("[EMAIL PROTECTED]", "The subject line" "This is the message content.\n") Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python To Send Emails Via Outlook Express

2004-12-22 Thread Lenard Lindstrom
[EMAIL PROTECTED] writes: > Hi Lenard, > Absolutely fantastic!! > That worked like a charm. > Now onto adapting it to send attachments. > Glad to be of help. Lenard Lindstrom -- http://mail.python.org/mailman/listinfo/python-list

Re: Python To Send Emails Via Outlook Express

2004-12-23 Thread Lenard Lindstrom
lpFiles)) Replace "cast(NULL, lpFiles)" with "lpFiles". > > > rc = MAPISendMail(0, 0, byref(msg), 0, 0) > if rc != SUCCESS_SUCCESS: > raise WindowsError, "MAPI error %i" % rc And that is it. The "cast(NULL, lpFiles)" was a way of assigning a null value to the lpFiles member of the MapiMessage structure. Using None did not work. But recasting a c_void_p(None) did. Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python To Send Emails Via Outlook Express

2004-12-23 Thread Lenard Lindstrom
> # No attachments > lpFiles = cast(NULL, lpMapiFileDesc) # Make NULL > > print "nFileCount ",nFileCount > > > recip = MapiRecipDesc(0, MAPI_TO, None, recipient, 0, None) > #msg = MapiMessage(0, subject, body, None, None, None, 0, > # cast(NULL, lpMapiRecipDesc), 1, pointer(recip), > # nFileCount, cast(NULL, lpMapiFileDesc)) > msg = MapiMessage(0, subject, body, None, None, None, 0, > cast(NULL, lpMapiRecipDesc), 1, pointer(recip), > nFileCount, lpFiles) > > > rc = MAPISendMail(0, 0, byref(msg), 0, 0) > if rc != SUCCESS_SUCCESS: > raise WindowsError, "MAPI error %i" % rc > > -- > > Thanks again for your help so far on this. I really appreciate it! > Have a safe and very merry Christmas. > And the same to you. Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python To Send Emails Via Outlook Express

2004-12-24 Thread Lenard Lindstrom
in zip(fda, attach): > fd.ulReserved = 0 > fd.flFlags = 0 > fd.nPosition = -1 > fd.lpszPathName = fa > fd.lpszFileName = None > fd.lpFileType = None > lpFiles = fda > else: > # No attachments > lpFiles = cast(NULL, lpMapiFileDesc) # Make NULL > > # Get the num

Re: [Pyrex] pyrex functions to replace a method (Re: replace a method in class: how?)

2006-06-28 Thread Lenard Lindstrom
s.update3=module_pyrex.pyrex_update_within_class # InstanceMethod is minimal. Additions may be to make the fn attribute readable and a __call__ method that calls fn directly. Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: magic names in python

2007-06-04 Thread Lenard Lindstrom
methods. Back to "magic names". Python is a consistent language. What may be special cased - "magic" - in another language is handled normally with Python's general purpose dynamic type system. In fact I can think of only one name I would call "magic": __fut

Re: magic names in python

2007-06-05 Thread Lenard Lindstrom
Steven D'Aprano wrote: > On Mon, 04 Jun 2007 22:19:35 +, Lenard Lindstrom wrote: > >> What is "magic" about __init__ and __repr__? They are identifiers just >> like "foo" or "JustAnotherClass". They have no special meaning to the

Re: magic names in python

2007-06-05 Thread Lenard Lindstrom
Steven D'Aprano wrote: > On Tue, 05 Jun 2007 18:08:31 +, Lenard Lindstrom wrote: > >> Steven D'Aprano wrote: >>> On Mon, 04 Jun 2007 22:19:35 +, Lenard Lindstrom wrote: >>> >>>> What is "magic" about __init__ and __repr__? T

Re: Help with PAM and ctypes

2007-06-11 Thread Lenard Lindstrom
ot;, os.getlogin(), pointer(c), > pointer(handle)) > > if retval != 0: > print "Couldn't start pam session" > sys.exit(-1) > > retval = pam_authenticate(handle, 0) > if retval == 21: > print "Authentication information cannot be recovered" > sys.exit(-1) > > print retval > If you are going to do any serious ctypes coding consider joining the ctypes mailing list at sourceforge.net . -- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with PAM and ctypes

2007-06-15 Thread Lenard Lindstrom
Chris AtLee wrote: > On Jun 11, 6:01 pm, Lenard Lindstrom <[EMAIL PROTECTED]> wrote: > [snip snip snip] >>> if __name__ == "__main__": >>> import getpass, os, sys >>> @conv_func >>> def my_conv(nMessages, messages, pResp

Re: getting the size of an object

2007-06-18 Thread Lenard Lindstrom
type instances also vary in length, but since long has no length property trying to figure out the size of a particular instance is harder. And types like list, map and unicode keep pointers to blocks of memory allocated separately. -- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: metaclasses and performance

2007-06-19 Thread Lenard Lindstrom
appens during attribute lookup is that an object's class is asserted to be an instance of type. Class test2 immediately passes the test since its type is "type". But test1's type is meta, so a function is called to check that meta is a subclass of "type". This may be t

Re: determine 32 or 64 bit architecture with python 2.2

2007-06-19 Thread Lenard Lindstrom
> (http://en.wikipedia.org/wiki/64-bit#64-bit_data_models ). > > Try > python -c "import struct; print struct.calcsize('P')" > instead. That calculates the size of a pointer. > How about: tuple.__itemsize__ since each tuple item is a pointer. -- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-22 Thread Lenard Lindstrom
ion of source code at module import time. The bytecodehack.macro module lets one define what amounts to inlined functions. IMO neither package represents a productive macro system. And I could find no other attempts to take Python macros beyond wishful thinking. So until some solid proposal for Python macros is put on the table any discussion of their merits is unproductive. I can suggest though that procedural macros are a natural starting point given the runtime nature of class and function creation. -- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing sound volume

2007-06-25 Thread Lenard Lindstrom
ID to 0. Apparently my assumption that it is always 0 was wrong. If that works I have a more flexible version of the module which actually searches for the speak line fader id. It also has a GetSpeakerVolume function. --- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-27 Thread Lenard Lindstrom
ions, and there are > implementations of Common Lisp with stack groups. > Those stack groups http://common-lisp.net/project/bknr/static/lmman/fd-sg.xml remind me of Python greenlets http://cheeseshop.python.org/pypi/greenlet . --- Lenard Lindstrom <[EMAIL PROTECTED]> -- htt

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-29 Thread Lenard Lindstrom
ons", which are > an understood notion in software engineering and by me when I write > software. > So documenting an assumption is more effective than removing the assumption using a with statement? -- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's "only one way to do it" philosophy isn't good?

2007-06-29 Thread Lenard Lindstrom
Douglas Alan wrote: > Lenard Lindstrom <[EMAIL PROTECTED]> writes: > >> Douglas Alan wrote: > >>> [I]n Python, you can be 100% sure that your files >>> will be closed in a timely manner without explicitly closing them, as >>> long as you are safe i

Re: Python's "only one way to do it" philosophy isn't good?

2007-07-01 Thread Lenard Lindstrom
Douglas Alan wrote: > Lenard Lindstrom <[EMAIL PROTECTED]> writes: > >> Explicitly clear the exception? With sys.exc_clear? > > Yes. Is there a problem with that? > As long as nothing tries to re-raise the exception I doubt it breaks anything: >>>

Re: ctype and functions that return a pointer to a structure

2007-07-01 Thread Lenard Lindstrom
) l_struct = cast(l_res, POINTER( Struct_Password ) ) POINTER wants a ctypes type as an argument. Struct_Password() is a Structure instance. A better way to do it is define the return type for getspnam: g_lib.getspnam.restype = POINTER( Struct_Password ) Now the function returns a structure pointer so the cast is unnecessary. --- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Lenard Lindstrom
Douglas Alan wrote: > Lenard Lindstrom <[EMAIL PROTECTED]> writes: > >>>> Explicitly clear the exception? With sys.exc_clear? > >>> Yes. Is there a problem with that? > >> As long as nothing tries to re-raise the exception I doubt it breaks &

Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Lenard Lindstrom
Douglas Alan wrote: > Lenard Lindstrom <[EMAIL PROTECTED]> writes: > >>> You don't necessarily want a function that raises an exception to >>> deallocate all of its resources before raising the exception, since >>> you may want access to these r

Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Lenard Lindstrom
Douglas Alan wrote: > Lenard Lindstrom <[EMAIL PROTECTED]> writes: > >>> Or are you suggesting that early in __main__.main(), when I wish to >>> debug something, I do something like: >>>__builtins__.open = __builtins__.file = MyFile >>> ?

Re: Python's "only one way to do it" philosophy isn't good?

2007-07-02 Thread Lenard Lindstrom
Douglas Alan wrote: > Lenard Lindstrom <[EMAIL PROTECTED]> writes: > >> But some things will make it into ISO Python. > > Is there a movement afoot of which I'm unaware to make an ISO standard > for Python? > Not that I know of. But it would seem any la

Re: Python's "only one way to do it" philosophy isn't good?

2007-07-05 Thread Lenard Lindstrom
gt; > f = some_file() > with f: > f.write("a bunch of stuff") > #insert code that assumes f is closed, but correctly this time > The with statement is designed to be safer. It contains an implicit try/finally that lets the file close itself in case of an exception. -- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-13 Thread Lenard Lindstrom
line_number += 1 if found: print "Found at", line_number else: print "Not found" # prints "Found at 2" --- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 3107 and stronger typing (note: probably a newbie question)

2007-07-14 Thread Lenard Lindstrom
Hendrik van Rooyen wrote: > "Lenard Lindstrom" <[EMAIL PROTECTED]> wrote: > > >> Pascal has no break, continue or return. Eiffel doesn't even have a >> goto. In such imperative languages boolean variables are used a lot. > > Thanks did no

Re: What is an instance and what isn't?

2007-05-24 Thread Lenard Lindstrom
class. The inspect module defines an isclass function as follows: def isclass(object): """Return true if the object is a class. Class objects provide these attributes: __doc__ documentation string __module__ name of module in which this class was defined""" return isinstance(object, types.ClassType) or \ hasattr(object, '__bases__') --- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: New-style classes and special methods

2007-05-30 Thread Lenard Lindstrom
27;m sure I'll eventually figure it out if I stare at the code hard > enough, but would totally appreciate any help I can get :) > Just ask. -- Lenard Lindstrom <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: Using Simple MAPI with MS Outlook 2007

2007-04-01 Thread Lenard Lindstrom
logs.msdn.com/stephen_griffin/archive/2006/11/03/the-intentional-memory-leak.aspx Hope this helps, Lenard Lindstrom -- http://mail.python.org/mailman/listinfo/python-list

Re: Character set woes with binary data

2007-04-01 Thread Lenard Lindstrom
; type and a way to deal with arrays of bytes, > independent of the string operators. > >Efficient handling of lists of bytes would do it. > > John Nagle array.array or ctypes.create_string_buffer. Lenard Lindstrom -- http://mail.python.org/mailman/listinfo/python-list

Re: operator overloading

2007-04-04 Thread Lenard Lindstrom
s not replaced with a generic wrapper that will call the __pow__ method. Instead myint keeps the slot function inherited from int. So myint may have a __pow__ method that adds, but it is never called when doing a **. Curiously C PyPy does what was expected: >pypy-c.exe Python 2.4.1 (pypy

Re: Calling Fortran from Python

2007-04-04 Thread Lenard Lindstrom
8.0, 12.0] >>> e1.value 0 >>> e2.value 0 I compile the SAMPLE example with mingw g77 3.4.5: g77 -shared -o sample.dll sample.for I had to take out the "INTENT(OUT)"s because g77 didn't like them. And "SAMPLE" became "sample_" in the dll. Also note that argument passing to Fortran subroutines is strictly pass-by-reference. Thus the ain pointer. Lenard Lindstrom -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling Fortran from Python

2007-04-05 Thread Lenard Lindstrom
Mangabasi wrote: > A little bit of googling solved the problem. instead of > sample = cdll.sample_dll.SAMPLE > > I used > > sample = windll.sample_dll.SAMPLE > > and now it seems to be working without error messages. > > Thanks a lot. > > I remember someone on the ctypes mailing

Re: AttributeError: 'tuple' object has no attribute 'encode'

2007-04-05 Thread Lenard Lindstrom
erikcw wrote: > Hi, > > I'm trying to build a SQL string > > sql = """INSERT INTO ag ('cid', 'ag', 'test') VALUES(%i, %s, %d)""", > (cid, ag, self.data[parent][child]['results']['test']) > I am guessing you want the string formatting operator here: sql = """...""" % (cid, ...) The comma creat