我一直在論壇上尋找答案,而我發現的最相似的是:Python: How to call class method from imported module? 「Self」 argument issue。但它不能解決我的問題。Python 2.7 - 如何從導入的模塊調用類方法? 「自我」的說法
我有2個腳本:1-X和2-Y。我需要與Y進口一些高清()到X,這裏是我的代碼,我導入和實例:
X腳本 - 它,我有一個名爲txtCorpus
變量,它是一個我打算操縱
import Y
from Y import PreProcessing
txtCorpus
def status_processing(txtCorpus):
instance = PreProcessing() #Here is where to instantiate the class contained within the Y script and where it has some defs that I need
myCorpus = instance.initial_processing(txtCorpus)
#After some other lines of operation ...
if __name__ == "__main__":
status_processing(txtCorpus)
現在腳本Ÿ
class PreProcessing():
@property
def text(self):
return self.__text
@text.setter
def text(self, text):
self.__text = text
tokens = None
def initial_processing(self):
#Operations
當我執行它的存在的方式,顯示了以下錯誤:
TypeError: initial_processing() takes exactly 1 argument (2 given)
當我這樣做myCorpus = instance.initial_processing()
,顯示以下錯誤:
AttributeError: PreProcessing instance has no attribute '_PreProcessing__text'
什麼是我必須實例的代碼時,我通過txtCorpus
作爲參數的工作方式?
'從Y import Y-class'那是無效的語法。請正確複製粘貼代碼。 –
@AlexHall我很確定這不是複製和粘貼錯誤。 –
'從Y進口Yclass'跟着行'txtCorpus'仍然是錯誤的。 –