473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can I undecorate a function?

The decorator as_string returns the decorated function's value as
string. In some instances I want to access just the function f,
though, and catch the values before they've been decorated.

Is this possible?

def as_string(f):
def anon(*args, **kwargs):
y = f(*args, **kwargs)
return str(y)
return anon

@as_string
def f(x):
return x * x

Matt
--
A better way of running series of SAS programs:
http://overlook.homelinux.net/wilson...asAndMakefiles
Jan 29 '07 #1
4 2785
Matthew Wilson wrote:
The decorator as_string returns the decorated function's value as
string. In some instances I want to access just the function f,
though, and catch the values before they've been decorated.

Is this possible?

def as_string(f):
def anon(*args, **kwargs):
y = f(*args, **kwargs)
return str(y)
return anon

@as_string
def f(x):
return x * x
Untested:
def as_string(f):
def anon(*args, **kwargs):
y = f(*args, **kwargs)
return str(y)
andon.the_function = f
return anon
@as_string
def f(x):
return x * x

print f.the_function(10)
Diez
Jan 29 '07 #2
MattIn some instances I want to access just the function f, though,
Mattand catch the values before they've been decorated.

def f(x):
return x * x

@as_string
def fs(x):
return f(x)

Call the one you want.

Skip
Jan 29 '07 #3
sk**@pobox.com wrote:
MattIn some instances I want to access just the function f, though,
Mattand catch the values before they've been decorated.

def f(x):
return x * x

@as_string
def fs(x):
return f(x)
or just
fs = as_string(f)

Kent
>
Call the one you want.

Skip
Jan 29 '07 #4
Matthew Wilson wrote:
The decorator as_string returns the decorated function's value as
string. In some instances I want to access just the function f,
though, and catch the values before they've been decorated.

Is this possible?

def as_string(f):
def anon(*args, **kwargs):
y = f(*args, **kwargs)
return str(y)
return anon

@as_string
def f(x):
return x * x
It's much simpler not to use the decorator syntax if you also want
access to the original function.

Simply declare f as a function, then assign decorator(f) to some other name.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note: http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

Jan 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Philips | last post by:
I recently had the need to sort a large number of lists of lists, and wondered if an improvement to the Decorate-Sort-Undecorate idiom is in the works. Ideally, I would like to sort the list of...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
1
by: Tom Anderson | last post by:
Subtitle: the war on temporary objects continues! The page on python performance tips on the python.org wiki (<http://wiki.python.org/moin/PythonSpeed/PerformanceTips>) suggests the following...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
8
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
18
by: Sean Connery | last post by:
According to dumpbin, my extern "C" __stdcall'ed functions are not decorated... According to depends they are not decorated... According to the documentation, (and previous releases of vc++), they...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.