Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 27th, 2004, 01:52 AM
mohikan mohikan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 36 mohikan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 m 39 sec
Reputation Power: 10
Send a message via ICQ to mohikan
function name from a variable

my problem is that,

no = 256
txt = "test"

def test_256():
print "this function name is test_256"


fname = "%s_%s"% (txt, no)

fname()

but it doesn't work.
how can I use a variable to function name


best regards

Reply With Quote
  #2  
Old July 27th, 2004, 02:52 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
How about this?
Code:
f1 = "hel"
f2 = "lo"
def hello(name): 
    print "Hello", name

my_func = eval("%s%s"%(f1, f2))

my_func("World")


grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #3  
Old July 27th, 2004, 03:08 AM
mohikan mohikan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 36 mohikan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 m 39 sec
Reputation Power: 10
Send a message via ICQ to mohikan
Thumbs up thanks

yes, that worked.

many thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > function name from a variable

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap