Calling a function from another function in Python

I'm starting to learn Python, but I have a problem with my code, and I was hoping someone could help. I have two functions, and I would like to name one function another. When I just tried calling the function, it seemed to be ignored, so I guess this is a problem with what I called it. Below is a snippet of my code.

# 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") 

Ed. I actually call the raw () function, it was just below the fragment. :)

+4
source share
1 answer

Try a simpler example:

 def func2(msg): return 'result of func2("' + func1(msg) + '")' def func1(msg): return 'result of func1("' + msg + '")' print func1('test') print func2('test') 

He prints:

 result of func1("test") result of func2("result of func1("test")") 

Note that the order of function definitions is intentionally canceled. The order of function definitions doesn't matter in Python.

You should indicate better what does not work for you.

+6
source

All Articles