Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

win32com - Python script neither running nor raising exception

I have a bizarre problem which for some reason I cannot now recreate. I'm hoping someone can help me understand what was happening and why it is not happening any more.

I have the following python script which creates a excel application object.

import win32com.client

try:
    print('line 4')
    obj = win32com.client.gencache.EnsureDispatch('excel.Application')
    print('line 6')
except Exception as e:
    print('line 8')
    print(e)

But when I ran it, the output was that it printed 'line 4' and then froze. It neither created the object and printed 'line 6', nor raised an exception and printed 'line 8'. It was also unresponsive to keyboard interrupts.

I ran Powershell and found out that there was an instance of EXCEL running. I closed it down and now the program runs fine and I can't get it to stop working in the same way that it did before, even if I start Microsoft Excel again.

Can anyone explain what was happening here? Is anyone able to recreate the above situation? I am running my scripts through spyder and jupiter notebooks. The problem occurred in both.

Can anyone explain how python can neither run a script nor raise an exception? Even if you can't explain how to solve this, I would appreciate it if anyone is able to tell me how to recreate this problem so I can look into it further.

question from:https://stackoverflow.com/questions/65923280/python-script-neither-running-nor-raising-exception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...