我开始学习 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() 函数,它就在代码片段的下方。:)