2013-04-11 52 views
-1

我已經借用了我正在使用的應用程序的一個python插件。這個插件有點過時了,因爲腳本中使用的方法已經改變了,我想試着弄清楚如何編輯腳本並對方法和函數進行適當的更新。有腳本中使用的4個模塊,我不知道哪一個包含方法和它的所有功能用更新的方法更新Python腳本?

基本上我有這樣一行:

layerEPSG = layer.srs().epsg() 
projectEPSG = self.canvas.mapRenderer().destinationSrs().epsg() 

srs()方法已更改爲crs()一些功能名稱也發生了變化(但仍然執行相同的操作)。我想以某種方式列出它們,看看是否有新名字epsg()destinationSrs()

這在我的腦海中是有道理的,但我沒有完全理解模塊,類,方法,函數是如何工作的一起。這是一個瞭解更多的項目。

任何幫助表示讚賞, 邁克

回答

1

您還可以使用help()來提供有關類或模塊的更多信息。舉個例子:

>>> class Fantasy(): 
...  def womble(self): 
...   print('I am a womble!') 
...  def dragon(self): 
...   """ Make the Dragon roar! """ 
...   print('I am a dragon...ROAR!') 
... 
>>> help(Fantasy) 
Help on class Fantasy in module __main__: 

class Fantasy(builtins.object) 
| Methods defined here: 
| 
| dragon(self) 
|  Make the Dragon roar! 
| 
| womble(self) 
| 
| ---------------------------------------------------------------------- 
| Data descriptors defined here: 
| 
| __dict__ 
|  dictionary for instance variables (if defined) 
| 
| __weakref__ 
|  list of weak references to the object (if defined) 

當然,如果類/模塊中有文檔字符串,這會更有用。

+1

謝謝尼克。這真的讓我走向了正確的方向。非常感激。 – Mike 2013-04-12 16:33:52

2

可以使用dir()發現模塊

import layers 
# print out the items in the module layers 
print dir(layers) 
print 

x = layer.crs() 
# print out the type that crs() returns 
print type(x) 
# print out the methods on the type returned by crs() 
print dir(x) 

的結構,也可以打開該模塊並閱讀其代碼。

+0

謝謝cmd。我沒有太多正式的編碼教育。只是自學成才。這是我學習的這些小工具,有助於澄清我缺少的一些東西。非常感謝。 – Mike 2013-04-12 16:35:01