A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/078843.html below:

def <dynamic function name> () syntax ?

def <dynamic function name> () syntax ? def <dynamic function name> () syntax ?Mike C. Fletcher mcfletch at home.com
Wed Apr 4 13:23:39 EDT 2001
>>> ns = {}
>>> sourceString = '''def abc( somearg ):\n\tprint somearg\n'''
>>> exec(sourceString) in  ns
>>> ns['abc']
<function abc at 0114CB8C>
>>> ns['abc']("hello")
hello
>>> 

HTH,
Mike

-----Original Message-----
From: Bruce Edge [mailto:bedge at troikanetworks.com]
Sent: Wednesday, April 04, 2001 12:52 PM
To: python-list at python.org
Subject: def <dynamic function name> () syntax ?


Can the follwoing be accomplished in Python?

I want to create a func named "abc":

>>> name="abc"

>>> eval ("name")
'abc'

>>> def eval ("name") ():
  File "<stdin>", line 1
    def eval ("name") ():
                   ^
SyntaxError: invalid syntax


Thanks, Bruce.
-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4