如何啓動一個Windows應用程序,如記事本使用Python NET?這是蟒蛇2.7.13我的源代碼:Python NET啓動一個Windows應用程序
C:\Python27>python.exe
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> import System
>>> type = System.Type.GetTypeFromProgID("Notepad.Application")
>>> System.Activator.CreateInstance(type)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
System.ArgumentNullException: Value cannot be null.
Parameter name: activationContext
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
您可以檢查如果'type'不是'None'?你確定ProgID =「Notepad.Application」嗎?它爲我返回null。 ''''也是Python中的保留關鍵字。 – denfromufa
這是一個古老的例子,我認爲是內部python錯誤與這個包的新版本System和實例化方式。 –
我不理解你 – denfromufa