我開始學習Python,但我遇到了一個與我的代碼有關的問題,並希望有人能夠提供幫助。我有兩個函數,我想從另一個函數中調用一個函數。當我簡單地嘗試調用函數時,它似乎被忽略了,所以我猜這是我如何調用它的問題。下面是我的代碼片段。從Python中的另一個函數調用函數
# Define the raw message function
def raw(msg):
s.send(msg+'\r\n')
# This is the part where I try to call the output function, but it
# does not seem to work.
output('msg', '[==>] '+msg)
return
# Define the output and error function
def output(type, msg):
if ((type == 'msg') & (debug == 1)) | (type != msg):
print('['+strftime("%H:%M:%S", gmtime())+'] ['+type.upper()+'] '+msg)
if type.lower() == 'fatal':
sys.exit()
return
# I will still need to call the output() function from outside a
# function as well. When I specified a static method for output(),
# calling output() outside a function (like below) didn't seem to work.
output('notice', 'Script started')
raw("NICK :PythonBot")
編輯。我實際上調用了raw()函數,它只是在代碼片段之下。 :)
你確定你打算在那裏使用'&'和'|'嗎? – 2012-07-23 22:04:21
「當我爲output()指定一個靜態方法」...等等,什麼? – 2012-07-23 22:05:47
你根本就沒有調用第一個函數...... – 2012-07-23 22:11:55