Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Concatenate String and Function

Is there a way in Python to cat a string and a function?

For example

def myFunction():
    a=(str(local_time[0]))
    return a

b="MyFunction"+myFunction

I get an error that I cannot concatenate a 'str' and 'function' object.

like image 216
user2295959 Avatar asked Apr 18 '13 16:04

user2295959


2 Answers

There are two possibilities:

If you are looking for the return value of myfunction, then:

print 'function: ' + myfunction() 

If you are looking for the name of myfunction then:

print 'function: ' + myfunction.__name__ 
like image 153
aldeb Avatar answered Oct 05 '22 15:10

aldeb


You need to call your function so that it actually returns the value you are looking for:

b="MyFunction"+myFunction()
like image 35
mjgpy3 Avatar answered Oct 05 '22 13:10

mjgpy3