亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: python wmi使用問題 [打印本頁]

作者: mysqllog    時間: 2012-05-08 11:58
標題: python wmi使用問題
本人沒有用過python,但是用過perl

有一個工作要使用wmi來完成,wmi模塊安裝

code:

import wmi
c = wmi.WMI()
for service in c.Win32_Service(Name="seclogon"):
  result, = service.StopService()
  if result == 0:
    print "Service", service.Name, "stopped"
  else:
    print "Some problem"
  break
else:
  print "Service not found"

但是在編譯時,發(fā)生錯誤:

AttributeError: 'module' object has no attribute 'WMI'


作者: anonymous0502    時間: 2012-05-08 14:32
好像沒有問題吧,解釋器提示符下
import wmi
dir(wmi)
看看
作者: mysqllog    時間: 2012-05-08 18:40
回復(fù) 2# anonymous0502

>>> import wmi
>>> dir(wmi)
['BASE', 'Dispatch', 'GetObject', 'PROTOCOL', 'ProvideConstants', 'Registry', 'SelfDeprecatingDict', 'WMI', 'WMI_EXCEPTIONS', '_DEBUG', '__VERSION__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_set', '_wmi_class', '_wmi_event', '_wmi_method', '_wmi_namespace', '_wmi_object', '_wmi_property', '_wmi_result', '_wmi_watcher', 'connect', 'connect_server', 'construct_moniker', 'datetime', 'from_1601', 'from_time', 'get_wmi_type', 'handle_com_error', 'obj', 'pywintypes', 're', 'signed_to_unsigned', 'struct', 'sys', 'to_time', 'warnings', 'wbemErrInvalidQuery', 'wbemErrTimedout', 'wbemFlagForwardOnly', 'wbemFlagReturnImmediately', 'x_access_denied', 'x_wmi', 'x_wmi_authentication', 'x_wmi_invalid_query', 'x_wmi_no_namespace', 'x_wmi_timed_out', 'x_wmi_uninitialised_thread']
>>>
這表示什么呢?正常?   
作者: anonymous0502    時間: 2012-05-08 19:30
有 'WMI',應(yīng)該是正常的吧
作者: fuliangcheng    時間: 2012-05-08 22:18
問題是WMI是個函數(shù)嗎,你把WMI當函數(shù)用了啊,應(yīng)該是其它的數(shù)據(jù)屬性吧
作者: happybj20008    時間: 2012-05-11 18:15
本帖最后由 happybj20008 于 2012-05-11 23:46 編輯

回復(fù) 1# mysqllog


今天第一天開始學習python就遇到這個錯誤提示,網(wǎng)上找了好久,最后發(fā)現(xiàn)我運行這段代碼的文件名是wmi.py,wmi庫腳本文件重名造成錯誤,改個名就好了。

PS. Python 3的print語法也變了,要加括號,也耽誤了我不少時間
   




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2