[python-win32] comObject set Null/None

Tim Golden mail at timgolden.me.uk
Tue Feb 22 10:20:25 CET 2011

On 22/02/2011 06:11, Jesse Kretschmer wrote:
> i wish to unset a com object value.  Specifically in active directory.
>   I have been using Tim Golden's active_directory module to connect to a
> user object.
> I have tried setting the value to '', None, and even chr(0).  I am at a
> loss.

[For those following at home, the code's basically a thin wrapper
around a pair of .Put / .SetInfo calls handing all the complexity
off to the pywin32 COM mechanism.]

Well I'm not quite sure why setting it to None / "" doesn't work, but
hopefully the following can provide a workaround:

import active_directory as ad

me = ad.find_user ()
me.PutEx (1, "telephoneNumber", "IRRELEVANT")


This should clear the telephoneNumber field; the first
param to PutEx is one of: Clear, Update, Append, Delete;
the second param is the field name; the third is usually
the value, but is irrelevant here. (I'd usually pass None
but I thought it might cloud the issue in this case)

Incidentally, it wasn't clear from your code fragment whether
you realised, but you can usually set AD fields directly by
referring to them as attributes:

   me.telephoneNumber = "504"

Passing None etc. doesn't work here either, hence the workaround


More information about the python-win32 mailing list