[python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
I have been using pywin32 successfully for years to control Excel. Now, suddenly I get errors executing the same code that has run previously. My python code controls Excel like this: import win32com.client xl = win32com.client.DispatchEx(Excel.Application) xl.DisplayAlerts = 0 xl.visible = 0 The last line('xl.visible = 0') now causes an error: type 'exceptions.AttributeError''win32com.gen_py.Microsoft Excel 14.0 Object Library._Application instance at 0x425283464' object has no attribute 'visible' [Function: glyphscript Line:63 | Function: __setattr__ Line:470] This error goes away if I use xl.Visible instead of xl.visible - notice the uppercase V. But then I get all sorts of other errors, in places that didn't error previously. Why would this code have worked for years, and then suddenly not work now? I am using Python 2.6.5 and pywin32-214 on 64 bit Windows 7. I uninstalled and reinstalled Python and pywin32, but the new errors persist. -Kurt Confidentiality Notice: This email may contain confidential and/or privileged information. If you are not the intended recipient of this message, please delete it immediately and inform the sender that you have received this message in error. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
On 17/07/2012 14:51, Kurt Munson wrote: I have been using pywin32 successfully for years to control Excel. Now, suddenly I get errors executing the same code that has run previously. [...] The last line(‘xl.visible = 0’) now causes an error: [...] This error goes away if I use xl.Visible instead of xl.visible – notice the uppercase V. But then I get all sorts of other errors, in places that didn’t error previously. You've almost certainly switched from using dynamic (or late-binding) Dispatch to using static (or early-binding) Dispatch. Dynamic dispatch simply hands off all attribute access to the underlying COM object which is not case-sensitive. Static dispatch creates an actual Python module which -- like all Python code -- is case-sensitive. You can force dynamic dispatch by using: code import win32com.client xl = win32com.client.dynamic.Dispatch(Excel.Application) /code Apart of the case-sensitivity, BTW, the clue is also in the traceback you posted which includes the win32com.gen_py prefix, indicating that it's using a generated Python module. TJG ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
[cc-ing the list back in so you get the benefit of more and greater intelligences...] On 17/07/2012 15:20, Kurt Munson wrote: I don't get it: I haven't made any changes to that Dispatch call in months! My code worked for months with the existing Dispatch method, up through yesterday afternoon, then began returning errors this morning. How could this be? Well maybe I'm wrong. Someone else might have a better idea, but it's a classic symptom of this issue. What does your Dispatch code look like? TJG ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
Dunno exactly what you mean by what's your Dispatch code look like. If you mean what am I doing with Excel via Python, it's like this: it creates an Excel spreadsheet, adds a bunch of content, formats cells, etc. All of this worked beautifully until this morning. Here is a little bit of the code I am using to control Excel: code import win32com.client xl = win32com.client.DispatchEx(Excel.Application) # other stuff xl.DisplayAlerts = 0 xl.Visible = 0 # more other stuff currentSheet.Range(A1:B1).EntireColumn.AutoFit # more more other stuff plotbutton = currentSheet.buttons.Add(300, 8, 80, 45) /code Incidentally, I tried changing the dispatch line to use dynamic dispatch using this code: code xl = win32com.client.dynamic.Dispatch(Excel.Application) /code ...and I still run into apparent case sensitivity, like not recognizing xl.visible, in lower case. I thought dynamic dispatch would remove case sensitivity. -Kurt -Original Message- From: Tim Golden [mailto:m...@timgolden.me.uk] Sent: Tuesday, July 17, 2012 10:27 AM To: Kurt Munson; python-win32@python.org Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously [cc-ing the list back in so you get the benefit of more and greater intelligences...] On 17/07/2012 15:20, Kurt Munson wrote: I don't get it: I haven't made any changes to that Dispatch call in months! My code worked for months with the existing Dispatch method, up through yesterday afternoon, then began returning errors this morning. How could this be? Well maybe I'm wrong. Someone else might have a better idea, but it's a classic symptom of this issue. What does your Dispatch code look like? TJG Confidentiality Notice: This email may contain confidential and/or privileged information. If you are not the intended recipient of this message, please delete it immediately and inform the sender that you have received this message in error. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
On 17/07/2012 16:05, Kurt Munson wrote: Dunno exactly what you mean by what's your Dispatch code look like. Well pretty much what you posted, in fact :) Incidentally, I tried changing the dispatch line to use dynamic dispatch using this code: code xl = win32com.client.dynamic.Dispatch(Excel.Application) /code ...and I still run into apparent case sensitivity, like not recognizing xl.visible, in lower case. I thought dynamic dispatch would remove case sensitivity. So did I: dump ActivePython 2.7.1.4 (ActiveState Software Inc.) based on Python 2.7.1 (r271:86832, Feb 7 2011, 11:30:38) [MSC v.1500 32 Type help, copyright, credits or license for more infor import win32com.client xl = win32com.client.dynamic.Dispatch(Excel.Application) xl.visible False xl.Visible False /dump whereas: dump xl2 = win32com.client.gencache.EnsureDispatch(Excel.Application) xl2.visible Traceback (most recent call last): File stdin, line 1, in module File c:\python27\lib\site-packages\win32com\client\__init__.py, line 462, in __getattr__ raise AttributeError('%s' object has no attribute '%s' % (repr(self), attr)) AttributeError: 'win32com.gen_py.Microsoft Excel 11.0 Object Library._Application instance at 0x58072680' object has no attribute 'visible' /dump Well I'm stumped. Hopefully someone more knowledgeable can chip in. TJG ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
-Original Message- Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously On 17/07/2012 16:05, Kurt Munson wrote: Dunno exactly what you mean by what's your Dispatch code look like. Well pretty much what you posted, in fact :) Incidentally, I tried changing the dispatch line to use dynamic dispatch using this code: code xl = win32com.client.dynamic.Dispatch(Excel.Application) /code ...and I still run into apparent case sensitivity, like not recognizing xl.visible, in lower case. I thought dynamic dispatch would remove case sensitivity. So did I: dump ActivePython 2.7.1.4 (ActiveState Software Inc.) based on Python 2.7.1 (r271:86832, Feb 7 2011, 11:30:38) [MSC v.1500 32 Type help, copyright, credits or license for more infor import win32com.client xl = win32com.client.dynamic.Dispatch(Excel.Application) xl.visible False xl.Visible False /dump whereas: dump xl2 = win32com.client.gencache.EnsureDispatch(Excel.Application) xl2.visible Traceback (most recent call last): File stdin, line 1, in module File c:\python27\lib\site-packages\win32com\client\__init__.py, line 462, in __getattr__ raise AttributeError('%s' object has no attribute '%s' % (repr(self), attr)) AttributeError: 'win32com.gen_py.Microsoft Excel 11.0 Object Library._Application instance at 0x58072680' object has no attribute 'visible' /dump Well I'm stumped. Hopefully someone more knowledgeable can chip in. [Graham Bloice said] Maybe remove the generated early binding .py for Excel in win32com\gen_py ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
There almost nothing in C:\Python26\Lib\site-packages\win32com\gen_py. In a subfolder \00020813---C000-0046x0x1x7, I have 30 .py and .pyc, all generated in the last day. Are you saying that they should be removed? -Kurt -Original Message- From: python-win32-bounces+kurt.munson=hbmncode@python.org [mailto:python-win32-bounces+kurt.munson=hbmncode@python.org] On Behalf Of Graham Bloice Sent: Tuesday, July 17, 2012 11:31 AM To: python-win32@python.org Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously -Original Message- Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously On 17/07/2012 16:05, Kurt Munson wrote: Dunno exactly what you mean by what's your Dispatch code look like. Well pretty much what you posted, in fact :) Incidentally, I tried changing the dispatch line to use dynamic dispatch using this code: code xl = win32com.client.dynamic.Dispatch(Excel.Application) /code ...and I still run into apparent case sensitivity, like not recognizing xl.visible, in lower case. I thought dynamic dispatch would remove case sensitivity. So did I: dump ActivePython 2.7.1.4 (ActiveState Software Inc.) based on Python 2.7.1 (r271:86832, Feb 7 2011, 11:30:38) [MSC v.1500 32 Type help, copyright, credits or license for more infor import win32com.client xl = win32com.client.dynamic.Dispatch(Excel.Application) xl.visible False xl.Visible False /dump whereas: dump xl2 = win32com.client.gencache.EnsureDispatch(Excel.Application) xl2.visible Traceback (most recent call last): File stdin, line 1, in module File c:\python27\lib\site-packages\win32com\client\__init__.py, line 462, in __getattr__ raise AttributeError('%s' object has no attribute '%s' % (repr(self), attr)) AttributeError: 'win32com.gen_py.Microsoft Excel 11.0 Object Library._Application instance at 0x58072680' object has no attribute 'visible' /dump Well I'm stumped. Hopefully someone more knowledgeable can chip in. [Graham Bloice said] Maybe remove the generated early binding .py for Excel in win32com\gen_py ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 Confidentiality Notice: This email may contain confidential and/or privileged information. If you are not the intended recipient of this message, please delete it immediately and inform the sender that you have received this message in error. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
Graham, Thanks for the suggestion - deleting the \win32com\gen_py .py and .pyc files solved the problem! It appears that my dispatch (whether static or dynamic) was using old generated py instead of regenerating. Why would this be? Either way, deleting the folder under \win32com\gen_py solved this problem. Thanks again for the help. -Kurt -Original Message- From: python-win32-bounces+kurt.munson=hbmncode@python.org [mailto:python-win32-bounces+kurt.munson=hbmncode@python.org] On Behalf Of Graham Bloice Sent: Tuesday, July 17, 2012 11:56 AM To: python-win32@python.org Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously -Original Message- From: Kurt Munson [mailto:kurt.mun...@hbmncode.com] Sent: 17 July 2012 16:46 To: Graham Bloice; python-win32@python.org Subject: RE: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously There almost nothing in C:\Python26\Lib\site-packages\win32com\gen_py. In a subfolder \00020813---C000-0046x0x1x7, I have 30 .py and .pyc, all generated in the last day. Are you saying that they should be removed? [Graham Bloice said] Have a quick look at them and if they are all for Excel interfaces, yes. I have a vague recollection that even dynamic dispatch will use the generated files if present. -Original Message- From: python-win32-bounces+kurt.munson=hbmncode@python.org [mailto:python-win32-bounces+kurt.munson=hbmncode@python.org] On Behalf Of Graham Bloice Sent: Tuesday, July 17, 2012 11:31 AM To: python-win32@python.org Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously -Original Message- Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously On 17/07/2012 16:05, Kurt Munson wrote: Dunno exactly what you mean by what's your Dispatch code look like. Well pretty much what you posted, in fact :) Incidentally, I tried changing the dispatch line to use dynamic dispatch using this code: code xl = win32com.client.dynamic.Dispatch(Excel.Application) /code ...and I still run into apparent case sensitivity, like not recognizing xl.visible, in lower case. I thought dynamic dispatch would remove case sensitivity. So did I: dump ActivePython 2.7.1.4 (ActiveState Software Inc.) based on Python 2.7.1 (r271:86832, Feb 7 2011, 11:30:38) [MSC v.1500 32 Type help, copyright, credits or license for more infor import win32com.client xl = win32com.client.dynamic.Dispatch(Excel.Application) xl.visible False xl.Visible False /dump whereas: dump xl2 = win32com.client.gencache.EnsureDispatch(Excel.Application) xl2.visible Traceback (most recent call last): File stdin, line 1, in module File c:\python27\lib\site-packages\win32com\client\__init__.py, line 462, in __getattr__ raise AttributeError('%s' object has no attribute '%s' % (repr(self), attr)) AttributeError: 'win32com.gen_py.Microsoft Excel 11.0 Object Library._Application instance at 0x58072680' object has no attribute 'visible' /dump Well I'm stumped. Hopefully someone more knowledgeable can chip in. [Graham Bloice said] Maybe remove the generated early binding .py for Excel in win32com\gen_py ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 Confidentiality Notice: This email may contain confidential and/or privileged information. If you are not the intended recipient of this message, please delete it immediately and inform the sender that you have received this message in error. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
-Original Message- From: python-win32-bounces+graham.bloice=trihedral@python.org [mailto:python-win32-bounces+graham.bloice=trihedral@python.org] On Behalf Of Kurt Munson Sent: 17 July 2012 17:08 To: python-win32@python.org Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously Graham, Thanks for the suggestion - deleting the \win32com\gen_py .py and .pyc files solved the problem! It appears that my dispatch (whether static or dynamic) was using old generated py instead of regenerating. Why would this be? Either way, deleting the folder under \win32com\gen_py solved this problem. Thanks again for the help. [Graham Bloice said] I don't know of a way to force regeneration, maybe the gencache module can do that, or possibly ComMakePy. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
Kurt Munson wrote: Thanks for the suggestion - deleting the \win32com\gen_py .py and .pyc files solved the problem! No, not really. What you did was HIDE the problem. The PROBLEM is that you are simply using the wrong name for that property. The property name is Visible with a capital V, and it always has been. You have been relying on the case-insensitivity that dynamic dispatch provides. In my opinion, that's a dangerous practice, and your experience here shows why. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously
Point taken, while trying to avoid a discussion on the validity of case sensitivity. 8) -Kurt -Original Message- From: python-win32-bounces+kurt.munson=hbmncode@python.org [mailto:python-win32-bounces+kurt.munson=hbmncode@python.org] On Behalf Of Tim Roberts Sent: Tuesday, July 17, 2012 12:31 PM To: Python-Win32 List Subject: Re: [python-win32] new Pywin32 errors stating 'object has no attribute' - and the code worked previously Kurt Munson wrote: Thanks for the suggestion - deleting the \win32com\gen_py .py and .pyc files solved the problem! No, not really. What you did was HIDE the problem. The PROBLEM is that you are simply using the wrong name for that property. The property name is Visible with a capital V, and it always has been. You have been relying on the case-insensitivity that dynamic dispatch provides. In my opinion, that's a dangerous practice, and your experience here shows why. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 Confidentiality Notice: This email may contain confidential and/or privileged information. If you are not the intended recipient of this message, please delete it immediately and inform the sender that you have received this message in error. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32