我开始学习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