| View previous topic :: View next topic |
| Author |
Message |
jomanda
Joined: 19 May 2006 Posts: 70 Location: Germany
|
Hi, if I have a string, such as 'invokeapp', how can i know that func named 'invokeapp' is exists as well?
That is i wanna invoke any func by string.
But i need to chech whether that func was exist. |
| |
|
|
|
|
Roombor
Joined: 02 Jun 2006 Posts: 111
|
exec 'try: invokeapp'; except: print" the function does not exist";else:print "it exists"'
Something like that
Exec and try-except are the keys to this problem |
| |
|
|
jomanda
Joined: 19 May 2006 Posts: 70 Location: Germany
|
| if do that, the python will raise a exceptiog about 'str hasnot callable' |
| |
|
|
Roombor
Joined: 02 Jun 2006 Posts: 111
|
| Why? |
| |
|
|
jomanda
Joined: 19 May 2006 Posts: 70 Location: Germany
|
| for a param string, there isnt callable on it. |
| |
|
|
WarChild
Joined: 24 Feb 2006 Posts: 46
|
| See globals() built-in function. |
| |
|
|
Roombor
Joined: 02 Jun 2006 Posts: 111
|
| I don't get what you mean |
| |
|
|
jomanda
Joined: 19 May 2006 Posts: 70 Location: Germany
|
at first, we may convert that string to func, which func can do this?
Like int ('12') |
| |
|
|
Roombor
Joined: 02 Jun 2006 Posts: 111
|
| No. You won't do it like this. I think there is no such function. |
| |
|
|
Klimapol
Joined: 27 May 2006 Posts: 134
|
jomanda, Do you really need to use this horrid exec stuff?
How about a dictionary of names to functions? The added benefit is that you can control which functions can be invoked |
| |
|
|
| Page 1 of 2 |
Goto page 1, 2 Next |
|