Problem with win32com

Alex Martelli alex at magenta.com
Thu Aug 10 16:01:37 EDT 2000


"didier.rano" <didier.rano at wanadoo.fr> wrote in message
news:8muoq0$pi4$1 at wanadoo.fr...
> Hello,
>
> I have a problem with win32com.
>
> This example is ok :
>
> from win32com.client import Dispatch
> dbEngine = Dispatch( "DAO.DBEngine")
>
> database = dbEngine.OpenDatabase( "c:\temp\essai.mdb")
> defs = database.TableDefs
>
> But, this other example is not ok:
>
> def fct():
>   from win32com.client import Dispatch
>   dbEngine = Dispatch( "DAO.DBEngine")
>
>   database = dbEngine.OpenDatabase( "c:\temp\essai.mdb")
>   return database
>
> database = fct()
> defs = database.TableDefs

I don't know enough DAO to be sure, but a problem could
be that in the second case, dbEngine being a local
variable, it will have been garbage-collected and
deallocated right after fct returns.  Don't know if
this IS a problem (it shouldn't be, if DAO is a well
designed COM Object-Model... but don't take the fact
that it's Microsoft-designed as proof it's good COM!-);
but it's the only substantial difference I can see
off-hand between the two cases.

Adding a 'global dbEngine' as the first statement in
fct would remove this semantic difference; try that --
it will help your diagnosis to see if it makes the
problem go away, or not...


Alex






More information about the Python-list mailing list