redho home | products | services
Web Design Forums

Web Design Forums  


Web Hosting, Web Design, Software and Web Development Forums  
 FAQFAQ   MemberlistArchive  Log inLog in   RegisterRegister 
         

how can i know that func named 'invokeapp' is exists


Goto page 1, 2  Next
 
Post new topic   Reply to topic    Web Design Forums -> Python programming forum
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.
  Reply with quote


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
  Reply with quote
jomanda



Joined: 19 May 2006
Posts: 70
Location: Germany
if do that, the python will raise a exceptiog about 'str hasnot callable'
  Reply with quote
Roombor



Joined: 02 Jun 2006
Posts: 111
Why?
  Reply with quote
jomanda



Joined: 19 May 2006
Posts: 70
Location: Germany
for a param string, there isnt callable on it.
  Reply with quote
WarChild



Joined: 24 Feb 2006
Posts: 46
See globals() built-in function.
  Reply with quote
Roombor



Joined: 02 Jun 2006
Posts: 111
I don't get what you mean
  Reply with quote
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')
  Reply with quote
Roombor



Joined: 02 Jun 2006
Posts: 111
No. You won't do it like this. I think there is no such function.
  Reply with quote
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
  Reply with quote
Page 1 of 2 Goto page 1, 2  Next
Post new topic   Reply to topic    Web Design Forums -> Python programming forum


Dubai Forums - Expat Help | Vegan Chat | Java Programming | Free 3D tutorials and 3d textures | Paris Forum | EU Forum
Free Dubai Classifieds | Free London Classifieds | Jobs in London

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

Powered by phpBB © 2001, 2005 phpBB Group