在python中,从另一个函数调用函数的正确格式是什么?我得到了';未定义';错误。
在GetToken函数中,我调用waitforit函数来等待crct邮件。它应该无限期运行,直到我收到正确的邮件。但是我得到了NameError:没有定义名称'GetToken'。如何在这里进行适当的函数调用?也给我一些建议,使代码结构合理在python中,从另一个函数调用函数的正确格式是什么?我得到了';未定义';错误。,python,function,calling-convention,Python,Function,Calling Convention,在GetToken函数中,我调用waitforit函数来等待crct邮件。它应该无限期运行,直到我收到正确的邮件。但是我得到了NameError:没有定义名称'GetToken'。如何在这里进行适当的函数调用?也给我一些建议,使代码结构合理 import win32com.client import time import itertools import threading from itertools import islice class Mainclass(object):
import win32com.client
import time
import itertools
import threading
from itertools import islice
class Mainclass(object):
def TryLogin(self):
tok = self.GetToken() #do something with it
def GetToken(self):
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
sliced_text = ""
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
subj =message.Subject
Fhandle = message.Body
if subj == "One Time Password":
for j in islice(Fhandle, 294, 300):
sliced_text+= str(j)
else:
self.Waitforit()
return sliced_text
def Waitforit(self):
time.sleep(10)
GetToken()
def main():
c = Mainclass()
c.TryLogin()
if __name__ == '__main__':
main()
self.GetToken()就像你在其他地方做的一样谢谢!我糊涂了!这些函数是
main类
类型上的方法。这就是为什么要使用self
访问它们。