Static typing—with annotations—function name & arguments, or result of call, or string

2020-10-22 Thread Samuel Marks
From my understanding, `ast.arguments` and `inspect.Signature` are the two builtin ways of defining the function name and arguments in a structured way. What I am creating is a way of configuring… well let's be specific to my use-case. I am building a way to configure TensorFlow. One whi

Re: Logging - have logger use caller's function name and line number

2018-12-29 Thread David
On Sun, 30 Dec 2018 at 05:58, Malcolm Greene wrote: > > I have a class method that adds additional context to many of the > class's log messages. Rather than calling, for example, logger.info( > 'message ...' ) I would like to call my_object.log( 'message ...' ) so > that this additional context

Re: Logging - have logger use caller's function name and line number

2018-12-29 Thread Peter Otten
Malcolm Greene wrote: > I have a class method that adds additional context to many of the > class's log messages. Rather than calling, for example, logger.info( > 'message ...' ) I would like to call my_object.log( 'message ...' ) so > that this additional context is managed in a single place. I'

Logging - have logger use caller's function name and line number

2018-12-29 Thread Malcolm Greene
I have a class method that adds additional context to many of the class's log messages. Rather than calling, for example, logger.info( 'message ...' ) I would like to call my_object.log( 'message ...' ) so that this additional context is managed in a single place. I'm actually doing that and its w

Re: function name

2010-04-29 Thread Peter Otten
Steven D'Aprano wrote: > Be aware though, that sys._getframe is marked as a private function (the > leading underscore), which means that: > > (1) It only exists in some Python implementations (CPython and possible > nothing else?); and $ jython Jython 2.2.1 on java1.6.0_0 Type "copyright", "cre

Re: function name

2010-04-28 Thread Steven D'Aprano
On Wed, 28 Apr 2010 21:03:36 +0200, Peter Otten wrote: > Richard Lamboj wrote: > >> is there any way to get the name from the actual called function, so >> that the function knows its own name? > import sys def my_name(): > ... return sys._getframe(1).f_code.co_name Be aware thou

Re: function name

2010-04-28 Thread Terry Reedy
On 4/28/2010 3:20 PM, Alf P. Steinbach wrote: * Richard Lamboj: is there any way to get the name from the actual called function, so that the function knows its own name? There was an earlier thread about this not very long ago. General consensus, as I recall, to replace function with an obj

Re: function name

2010-04-28 Thread Tim Chase
On 04/28/2010 01:50 PM, Emile van Sebille wrote: On 4/28/2010 11:44 AM Richard Lamboj said... is there any way to get the name from the actual called function, so that the function knows its own name? >>> def test():pass ... >>> dir(test) ['__call__', '__class__', '__closure__', '__code_

Re: function name

2010-04-28 Thread Alf P. Steinbach
* Richard Lamboj: is there any way to get the name from the actual called function, so that the function knows its own name? There was an earlier thread about this not very long ago. General consensus, as I recall, to replace function with an object of a class (possibly with __call__ method

Re: function name

2010-04-28 Thread Brendan Abel
On Apr 28, 11:44 am, Richard Lamboj wrote: > Hello, > > is there any way to get the name from the actual called function, so that the > function knows its own name? > > Kind Regards, > > Richi If you want to get the function name from within the function itself, chec

Re: function name

2010-04-28 Thread Sridhar Ratnakumar
On 2010-04-28, at 11:50 AM, Emile van Sebille wrote: > On 4/28/2010 11:44 AM Richard Lamboj said... >> >> Hello, >> >> is there any way to get the name from the actual called function, so that the >> function knows its own name? >> >> Kind Regards, >> >> Richi > ActivePython 2.6.1.1 (ActiveSt

Re: function name

2010-04-28 Thread Peter Otten
Richard Lamboj wrote: > is there any way to get the name from the actual called function, so that > the function knows its own name? >>> import sys >>> def my_name(): ... return sys._getframe(1).f_code.co_name ... >>> def rumpelstilzchen(): ... print u"Ach, wie gut dass niemand weiß, dass

Re: function name

2010-04-28 Thread Emile van Sebille
On 4/28/2010 11:44 AM Richard Lamboj said... Hello, is there any way to get the name from the actual called function, so that the function knows its own name? Kind Regards, Richi ActivePython 2.6.1.1 (ActiveState Software Inc.) based on Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v

function name

2010-04-28 Thread Richard Lamboj
Hello, is there any way to get the name from the actual called function, so that the function knows its own name? Kind Regards, Richi -- http://mail.python.org/mailman/listinfo/python-list

Re: Function name unchanged in error message

2010-02-01 Thread Gabriel Genellina
En Sat, 30 Jan 2010 06:28:19 -0300, Peter Otten <__pete...@web.de> escribió: Gabriel Genellina wrote: En Fri, 29 Jan 2010 13:09:40 -0300, Michele Simionato escribió: On Jan 29, 2:30 pm, andrew cooke wrote: Is there any way to change the name of the function in an error message? In the ex

Re: Function name unchanged in error message

2010-01-30 Thread Steven D'Aprano
On Sat, 30 Jan 2010 14:26:43 -0800, andrew cooke wrote: > On Jan 29, 11:50 am, exar...@twistedmatrix.com wrote: >> new.function and new.code will let you construct new objects with >> different values (and copying over whichever existing attributes you >> want to preserve). > > unfortunately new

Re: Function name unchanged in error message

2010-01-30 Thread andrew cooke
On Jan 29, 1:09 pm, Michele Simionato wrote: > On Jan 29, 2:30 pm, andrew cooke wrote: > > > Is there any way to change the name of the function in an error > > message?  In the example below I'd like the error to refer to bar(), > > for example (the motivation is related function decorators - I'

Re: Function name unchanged in error message

2010-01-30 Thread andrew cooke
On Jan 30, 7:17 pm, andrew cooke wrote: > On Jan 29, 5:37 pm, "Gabriel Genellina" > wrote: > > > The decorator module is a very fine addition to anyone's tool set -- but   > > in this case it is enough to use the wraps() function from the functools   > > standard module. > > ah, thanks!  i though

Re: Function name unchanged in error message

2010-01-30 Thread andrew cooke
On Jan 29, 11:50 am, exar...@twistedmatrix.com wrote: > new.function and new.code will let you construct new objects with > different values (and copying over whichever existing attributes you > want to preserve). unfortunately new is deprecated and dropped from 3. i can't see how the same functi

Re: Function name unchanged in error message

2010-01-30 Thread andrew cooke
On Jan 29, 5:37 pm, "Gabriel Genellina" wrote: > The decorator module is a very fine addition to anyone's tool set -- but   > in this case it is enough to use the wraps() function from the functools   > standard module. ah, thanks! i thought something like this existed in the standard lib, but c

Re: Function name unchanged in error message

2010-01-30 Thread andrew cooke
On Jan 29, 11:22 am, Peter Otten <__pete...@web.de> wrote: > The name is looked up in the code object. As that is immutable you have to > make a new one: [details snipped] thanks very much! sorry i didn't reply earlier - been travelling. (also, thanks to any other replies - i'm just reading thro

Re: Function name unchanged in error message

2010-01-30 Thread Peter Otten
Gabriel Genellina wrote: > En Fri, 29 Jan 2010 13:09:40 -0300, Michele Simionato > escribió: > >> On Jan 29, 2:30 pm, andrew cooke wrote: >>> Is there any way to change the name of the function in an error >>> message? In the example below I'd like the error to refer to bar(), >>> for example

Re: Function name unchanged in error message

2010-01-29 Thread Gabriel Genellina
En Fri, 29 Jan 2010 13:09:40 -0300, Michele Simionato escribió: On Jan 29, 2:30 pm, andrew cooke wrote: Is there any way to change the name of the function in an error message? In the example below I'd like the error to refer to bar(), for example (the motivation is related function decora

Re: Function name unchanged in error message

2010-01-29 Thread Michele Simionato
On Jan 29, 2:30 pm, andrew cooke wrote: > Is there any way to change the name of the function in an error > message?  In the example below I'd like the error to refer to bar(), > for example (the motivation is related function decorators - I'd like > the wrapper function to give the same name) Us

Re: Function name unchanged in error message

2010-01-29 Thread exarkun
On 02:10 pm, c...@rebertia.com wrote: On Fri, Jan 29, 2010 at 5:30 AM, andrew cooke wrote: Is there any way to change the name of the function in an error message? �In the example below I'd like the error to refer to bar(), for example (the motivation is related function decorators - I'd like t

Re: Function name unchanged in error message

2010-01-29 Thread Peter Otten
andrew cooke wrote: > Is there any way to change the name of the function in an error > message? In the example below I'd like the error to refer to bar(), > for example (the motivation is related function decorators - I'd like > the wrapper function to give the same name) > def foo(): > ..

Re: Function name unchanged in error message

2010-01-29 Thread Chris Rebert
On Fri, Jan 29, 2010 at 5:30 AM, andrew cooke wrote: > Is there any way to change the name of the function in an error > message?  In the example below I'd like the error to refer to bar(), > for example (the motivation is related function decorators - I'd like > the wrapper function to give the s

Re: Function name unchanged in error message

2010-01-29 Thread Jean-Michel Pichavant
andrew cooke wrote: Is there any way to change the name of the function in an error message? In the example below I'd like the error to refer to bar(), for example (the motivation is related function decorators - I'd like the wrapper function to give the same name) def foo(): ...

Function name unchanged in error message

2010-01-29 Thread andrew cooke
Is there any way to change the name of the function in an error message? In the example below I'd like the error to refer to bar(), for example (the motivation is related function decorators - I'd like the wrapper function to give the same name) >>> def foo(): ... return 7 ... >>> foo.__name

Re: How to get a unique function name for methods

2009-10-29 Thread Terry Reedy
Christian Heimes wrote: Philip Guo wrote: Does anyone know how to get this information either from a code object or from a related object? I am hacking the interpreter, so I have full access to everything. Does this help? class A(object): ... def method(self): ... pass ... A.m

Re: How to get a unique function name for methods

2009-10-29 Thread Terry Reedy
Philip Guo wrote: Hi all, This is my first post, so sorry for the n00bish question. Let's say I have 2 classes with the same __init__ method defined in a file foo.py: class A: def __init__(self): pass class B: def __init__(self): pass For the purpose of a code analysis, I need

Re: How to get a unique function name for methods

2009-10-29 Thread Christian Heimes
Philip Guo wrote: > Does anyone know how to get this information either from a code object or > from a related object? I am hacking the interpreter, so I have full access > to everything. Does this help? >>> class A(object): ... def method(self): ... pass ... >>> A.method.im_class >

How to get a unique function name for methods

2009-10-29 Thread Philip Guo
Hi all, This is my first post, so sorry for the n00bish question. Let's say I have 2 classes with the same __init__ method defined in a file foo.py: class A: def __init__(self): pass class B: def __init__(self): pass For the purpose of a code analysis, I need to get a UNIQUE name f

Re: How to refer to class name and function name in a python program?

2009-10-05 Thread Gabriel Genellina
En Mon, 28 Sep 2009 22:54:55 -0300, Peng Yu escribió: On Sun, Sep 20, 2009 at 12:43 PM, Benjamin Kaplan wrote: On Sun, Sep 20, 2009 at 12:43 PM, Peng Yu wrote: On Sun, Sep 20, 2009 at 11:32 AM, Vijayendra Bapte wrote: class A: @echo def __repr__(self): pass What does @ech

Re: How to refer to class name and function name in a python program?

2009-09-28 Thread Peng Yu
On Sun, Sep 20, 2009 at 12:43 PM, Benjamin Kaplan wrote: > On Sun, Sep 20, 2009 at 12:43 PM, Peng Yu wrote: >> On Sun, Sep 20, 2009 at 11:32 AM, Vijayendra Bapte >> wrote: >>> On Sep 20, 8:38 pm, Peng Yu wrote: Hi, I have the following code. I want to change the function body of

Re: How to refer to class name and function name in a python program?

2009-09-20 Thread alex23
Peng Yu wrote: > What does @echo mean? Have you read _any_ of the documentation? Or is this all an exercise in seeing if you can convince a group of disparate strangers to teach you Python for free? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to refer to class name and function name in a python program?

2009-09-20 Thread Benjamin Kaplan
On Sun, Sep 20, 2009 at 12:43 PM, Peng Yu wrote: > On Sun, Sep 20, 2009 at 11:32 AM, Vijayendra Bapte > wrote: >> On Sep 20, 8:38 pm, Peng Yu wrote: >>> Hi, >>> >>> I have the following code. I want to change the function body of >>> __repr__ to something like >>> >>>     return 'In %s::%s' % ($

Re: How to refer to class name and function name in a python program?

2009-09-20 Thread r
On Sep 20, 10:38 am, Peng Yu wrote: > Hi, > > I have the following code. I want to change the function body of > __repr__ to something like PS: Methods get angry when you refer to them as functions . You see, methods feel that they are more than a mere lowly function, and have developed a superi

Re: How to refer to class name and function name in a python program?

2009-09-20 Thread Peng Yu
On Sun, Sep 20, 2009 at 11:32 AM, Vijayendra Bapte wrote: > On Sep 20, 8:38 pm, Peng Yu wrote: >> Hi, >> >> I have the following code. I want to change the function body of >> __repr__ to something like >> >>     return 'In %s::%s' % ($class_name, $function_name) >> >> I'm wondering what I should

Re: How to refer to class name and function name in a python program?

2009-09-20 Thread Vijayendra Bapte
On Sep 20, 8:38 pm, Peng Yu wrote: > Hi, > > I have the following code. I want to change the function body of > __repr__ to something like > >     return 'In %s::%s' % ($class_name, $function_name) > > I'm wondering what I should write for $class_name and $function_name in > python. > > Regards,

Re: How to refer to class name and function name in a python program?

2009-09-20 Thread Duncan Booth
Peng Yu wrote: > Hi, > > I have the following code. I want to change the function body of > __repr__ to something like > > return 'In %s::%s' % ($class_name, $function_name) > > I'm wondering what I should write for $class_name and $function_name > in python. > > Regards, > Peng > > cla

Re: How to refer to class name and function name in a python program?

2009-09-20 Thread r
On Sep 20, 10:38 am, Peng Yu wrote: > Hi, > > I have the following code. I want to change the function body of > __repr__ to something like > >     return 'In %s::%s' % ($class_name, $function_name) > > I'm wondering what I should write for $class_name and $function_name in > python. > > Regards,

How to refer to class name and function name in a python program?

2009-09-20 Thread Peng Yu
Hi, I have the following code. I want to change the function body of __repr__ to something like return 'In %s::%s' % ($class_name, $function_name) I'm wondering what I should write for $class_name and $function_name in python. Regards, Peng class A: def __init__(self): pass def __

Re: module name versus function name resolution conflict.

2009-07-07 Thread Dave Angel
rocky wrote: Someone recently reported a problem in pydb where a function defined in his program was conflicting with a module name that pydb uses. I think I understand what's wrong, but I don't have any elegant solutions to the problem. Suggestions would be appreciated. In a nutshell, here's th

Re: module name versus function name resolution conflict.

2009-07-07 Thread rocky
On Jul 7, 2:33 am, Peter Otten <__pete...@web.de> wrote: > rocky wrote: > > Someone recently reported a problem in pydb where a function defined > > in his program was conflicting with amodulenamethat pydb uses. I > > think I understand what's wrong, but I don't have any elegant > > solutions to th

Re: module name versus function name resolution conflict.

2009-07-06 Thread Peter Otten
rocky wrote: > Someone recently reported a problem in pydb where a function defined > in his program was conflicting with a module name that pydb uses. I > think I understand what's wrong, but I don't have any elegant > solutions to the problem. Suggestions would be appreciated. > > In a nutshell

module name versus function name resolution conflict.

2009-07-06 Thread rocky
Someone recently reported a problem in pydb where a function defined in his program was conflicting with a module name that pydb uses. I think I understand what's wrong, but I don't have any elegant solutions to the problem. Suggestions would be appreciated. In a nutshell, here's the problem: In

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-04-03 Thread srepmub
On Mar 30, 4:36 pm, Michele Simionato wrote: > On Mar 30, 3:31 pm, srepmub wrote: > > > for the record, the input forShedskinis pure Python, so there is no > > added syntax or optional type declaration system. that said, I can > > understand it not being on some list for not being production-read

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-30 Thread Tim Golden
Steven D'Aprano wrote: On Mon, 30 Mar 2009 09:46:40 +0200, Hendrik van Rooyen wrote: Its kind of sad to see unladen swallow, which is just a promise, on the list, while Shedskin, which isn't, is ignored. Does this say something about big corporations vs the small man? No, what it says is tha

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-30 Thread Steven D'Aprano
On Mon, 30 Mar 2009 09:46:40 +0200, Hendrik van Rooyen wrote: > Its kind of sad to see unladen swallow, which is just a promise, on the > list, while Shedskin, which isn't, is ignored. > > Does this say something about big corporations vs the small man? No, what it says is that I had just read a

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-30 Thread Michele Simionato
On Mar 30, 3:31 pm, srepmub wrote: > for the record, the input for Shedskin is pure Python, so there is no > added syntax or optional type declaration system. that said, I can > understand it not being on some list for not being production-ready. > > thanks, > mark dufour. But does ShedSkin accep

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-30 Thread srepmub
> > Its kind of sad to see unladen swallow, which is just > > a promise, on the list, whileShedskin, which isn't, > > is ignored. > > > Does this say something about big corporations > > vs the small man? > > I think the programs on the list were supposed to actually implement > Python and extensi

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-30 Thread Paul Rubin
"Hendrik van Rooyen" writes: > Its kind of sad to see unladen swallow, which is just > a promise, on the list, while Shedskin, which isn't, > is ignored. > > Does this say something about big corporations > vs the small man? I think the programs on the list were supposed to actually implement P

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-30 Thread Hendrik van Rooyen
"Steven D'Aprano" wrote: >Oh noes!!! Python will be just like nearly every other language!!! > >Including Python. There are already at least thirteen implementations >(forks) of Python (although some of these are defunct or unmaintained): > >CPython >Jython >IronPython >Python for .NET >CLPytho

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-28 Thread Aaron Brady
On Mar 29, 12:23 am, Steven D'Aprano wrote: > On Fri, 27 Mar 2009 19:57:41 -0700, Aaron Brady wrote: > > I see how c-l-py doesn't represent the full interests of Python, > > Python is a *programming language*. It doesn't have interests. It just > sits there, a bunch of bits on a disk, waiting to b

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-28 Thread Steven D'Aprano
On Fri, 27 Mar 2009 19:57:41 -0700, Aaron Brady wrote: > I see how c-l-py doesn't represent the full interests of Python, Python is a *programming language*. It doesn't have interests. It just sits there, a bunch of bits on a disk, waiting to be used. *People* have interests, and Python is a me

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Aahz
In article , andrew cooke wrote: > >c.l.python used to be the core of a community built around a language. It >no longer is. It is a very useful place, where some very helpful and >knowledgeable people hang out and give advice, but instead of representing >the full interests of the Python commun

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread skip
Andrew> c.l.python used to be the core of a community built around a Andrew> language. It no longer is. It is a very useful place, where Andrew> some very helpful and knowledgeable people hang out and give Andrew> advice, but instead of representing the full interests of the

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Aaron Brady
On Mar 27, 8:15 pm, "andrew cooke" wrote: > Erik Max Francis wrote: > > [...] > > > And made all purdy-like: > > >    http://www.alcyone.com/tmp/python-list%20traffic.pdf > > That's very pretty, but neither the volume of posts, nor the quality of > the people posting here is really what I was talk

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Albert Hopkins
On Fri, 2009-03-27 at 21:15 -0400, andrew cooke wrote: [...] > c.l.python used to be the core of a community built around a language. It > no longer is. It is a very useful place, where some very helpful and > knowledgeable people hang out and give advice, but instead of representing > the full

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread andrew cooke
Erik Max Francis wrote: [...] > And made all purdy-like: > > http://www.alcyone.com/tmp/python-list%20traffic.pdf That's very pretty, but neither the volume of posts, nor the quality of the people posting here is really what I was talking about. I don't think I explained very well, but seei

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Erik Max Francis
Albert Hopkins wrote: I agree. If the argument is simply that some devs no longer hang here but do on -dev than that's not declining to me, especially as the amount of traffic on -dev increases. That's ordinary. Same for people coming and going. For me declining means the rate of (non-spam) po

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Aahz
In article , Nick Craig-Wood wrote: > >c.l.py is my favourite usenet group and has been for some time. I've >been doing usenet for 16 years now! Newbie. ;-) -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit an

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Nick Craig-Wood
Aahz wrote: > Well, yes, but that's simply the nature of online fora (I originally > wrote "nature of Usenet", but I think it's more general than that). From > my POV, if you're going to call it a "decline", you need to provide more > evidence than some people leaving and others arriving. I

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread skip
Albert> For me declining means the rate of (non-spam) posts is steadily Albert> dropping over time. I know this wasn't the main point of your post, but if you subscribe to python-list@python.org or read it via a mail-to-news gateway like Gmane I think you will find the ratio of spam to ha

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Albert Hopkins
On Fri, 2009-03-27 at 10:47 -0700, Aahz wrote: > In article , > andrew cooke wrote: > >Aahz wrote: > >> > >> Excuse me? What decline of this newsgroup? > > > >Hmmm. It's hard to respond to this without implicitly criticising others > >here, which wasn't my point at all. But my personal impress

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread skip
Aahz> Excuse me? What decline of this newsgroup? Andrew> But my personal impression is that over the years various Andrew> people who used to post here now stay pretty firmly in the dev Andrew> group, while others seem to have disappeared more or less Andrew> completely

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Tim Chase
Aahz wrote: In article , andrew cooke wrote: you are trying to do very "deep" things that most people do not do with python. that does not mean that there are no solutions, just that you have to find them yourself (especially with the decline of this newsgroup). Excuse me? What decline of t

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Aahz
In article , andrew cooke wrote: >Aahz wrote: >> >> Excuse me? What decline of this newsgroup? > >Hmmm. It's hard to respond to this without implicitly criticising others >here, which wasn't my point at all. But my personal impression is that >over the years various people who used to post here

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread andrew cooke
Aahz wrote: > Excuse me? What decline of this newsgroup? Hmmm. It's hard to respond to this without implicitly criticising others here, which wasn't my point at all. But my personal impression is that over the years various people who used to post here now stay pretty firmly in the dev group, w

c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread Aahz
In article , andrew cooke wrote: > >you are trying to do very "deep" things that most people do not do with >python. that does not mean that there are no solutions, just that you >have to find them yourself (especially with the decline of this >newsgroup). Excuse me? What decline of this newsgr

Re: Mangle function name with decorator?

2009-03-25 Thread J. Cliff Dyer
On Wed, 2009-03-18 at 08:18 -0700, Adam wrote: > On Mar 18, 10:33 am, "J. Cliff Dyer" wrote: > > You might be interested in redefining __getattribute__(self, attr) on > > your class. This could operate in conjunction with the hash tables > > (dictionaries) mentioned by andrew cooke. i.e. (untest

Re: Mangle function name with decorator?

2009-03-18 Thread Aaron Brady
On Mar 18, 8:47 am, Adam wrote: > On Mar 17, 1:49 pm, Aaron Brady wrote: > > > > > You would need a unique attribute to look for on values in the > > dictionary, which means you'd need to detect what functions you are > > renaming; possibly by using a decorator to mark them.  (Untested:) > > > cl

Re: Mangle function name with decorator?

2009-03-18 Thread R. David Murray
Adam wrote: > David, would you believe that I just posted about this very idea, It > doesn't seem to have shown up yet, though. This idea works from the > perspective of being trivially easy to implement. I can easily write > a metaclass that looks in the namespace for methods with names that >

Re: Mangle function name with decorator?

2009-03-18 Thread andrew cooke
Adam wrote: > Hey, Cliff. Thanks for sharing this idea. Unfortunately, providing a > way to actually call the method with the mangled name is relatively > easy, and there are options there. The real issue, to me, seems to be > finding a way to prevent Python from eating all but the last version

Re: Mangle function name with decorator?

2009-03-18 Thread Michele Simionato
On Mar 18, 4:18 pm, Adam wrote: > Hey, Cliff.  Thanks for sharing this idea.  Unfortunately, providing a > way to actually call the method with the mangled name is relatively > easy, and there are options there.  The real issue, to me, seems to be > finding a way to prevent Python from eating all

Re: Mangle function name with decorator?

2009-03-18 Thread Adam
On Mar 18, 11:11 am, "R. David Murray" wrote: > I don't have any wisdom on the metaclass/decorator stuff, but what > about slightly reformulating the interface?  Instead of having the > programmer type, eg: > >     @GET >     def foo(self): pass > >     @POST >     def foo(self): pass > > have the

Re: Mangle function name with decorator?

2009-03-18 Thread Adam
On Mar 18, 10:33 am, "J. Cliff Dyer" wrote: > You might be interested in redefining __getattribute__(self, attr) on > your class.  This could operate in conjunction with the hash tables > (dictionaries) mentioned by andrew cooke.  i.e. (untested code): > > class C(object): >     def __init__(self)

Re: Mangle function name with decorator?

2009-03-18 Thread R. David Murray
> class foo_controller(Controller): > __metaclass__= ControllerMetaclass > def __init__(self, action, method = None): > self.action = action > self.method = method > > > def foo(self): > print "in foo()" > > @get_only > def foo(self): > print "

Re: Mangle function name with decorator?

2009-03-18 Thread J. Cliff Dyer
You might be interested in redefining __getattribute__(self, attr) on your class. This could operate in conjunction with the hash tables (dictionaries) mentioned by andrew cooke. i.e. (untested code): class C(object): def __init__(self): self._get_table = {} self._post_table

Re: Mangle function name with decorator?

2009-03-18 Thread Adam
On Mar 17, 1:49 pm, Aaron Brady wrote: > You would need a unique attribute to look for on values in the > dictionary, which means you'd need to detect what functions you are > renaming; possibly by using a decorator to mark them.  (Untested:) > > class X( metaclass= M ): >   @mark( 'A' ) >   def

Re: Mangle function name with decorator?

2009-03-17 Thread Michele Simionato
I forgot; people interested in metaclasses in Python 3.0 will want to read this paper: http://www.artima.com/weblogs/viewpost.jsp?thread=236234 -- http://mail.python.org/mailman/listinfo/python-list

Re: Mangle function name with decorator?

2009-03-17 Thread Michele Simionato
On Mar 17, 7:45 pm, Aaron Brady wrote: > (Perhaps someday, we will be able to write: > def dec( namespace ): >   def outer( fun ): >     if fun.__name__ in namespace: >       namespace[ dup_var ]= namespace[ fun.__name__ ] >     return fun >   return outer > It allows us to see if there's a prior

Re: Mangle function name with decorator?

2009-03-17 Thread Aaron Brady
at bottom On Mar 17, 12:54 pm, "andrew cooke" wrote: > ah, ok.  then yes, you can do that with decorators.  you'd need hash > tables or something similar in a metaclass.  then the decorator would take > the given function, stick it in the appropriate hash table, and return a > function that does t

Re: Mangle function name with decorator?

2009-03-17 Thread andrew cooke
ah, ok. then yes, you can do that with decorators. you'd need hash tables or something similar in a metaclass. then the decorator would take the given function, stick it in the appropriate hash table, and return a function that does the dispatch (ie at run time does the lookup from the hash tab

Re: Mangle function name with decorator?

2009-03-17 Thread Aaron Brady
On Mar 17, 12:20 pm, Adam wrote: > Thanks, Andrew.  I'm trying to accomplish something with a > metaprogramming flavor, where, for the convenience of the programmer > and the clarity of code, I'd like to have a decorator or some other > mechanism do twiddling behind the scenes to make a class do s

Re: Mangle function name with decorator?

2009-03-17 Thread Adam
Thanks, Andrew. I'm trying to accomplish something with a metaprogramming flavor, where, for the convenience of the programmer and the clarity of code, I'd like to have a decorator or some other mechanism do twiddling behind the scenes to make a class do something it wouldn't normally do. Here's

Re: Mangle function name with decorator?

2009-03-17 Thread andrew cooke
Adam wrote: > class A(object): > def __init__(self, method, usebar = False): > self.method = method > self.usebar = usebar > > def __call__(self): > if self.usebar == True: > mangled_name = "_bar_" + self.method > if hasattr(self, mangled_name

Mangle function name with decorator?

2009-03-17 Thread Adam
I am using Python 2.5, and I would like to write a decorator (or using some other elegant, declarative approach) to mangle the name of function in a class. I would like to be able to have two methods declared with the same name, but one of them will have a decorator (or whatever) that will change

Re: Function name limit in Python ?

2009-02-14 Thread Steven D'Aprano
Linuxguy123 wrote: > Excuse my ignorance, but is there a limit to the size of function names > in Python ? > > I named a function getSynclientVersion() and I got an error when I > called it. No no, don't tell us what error you got! I love guessing games. I'm guessing you got either a SyntaxErr

Re: Function name limit in Python ?

2009-02-14 Thread Albert Hopkins
On Sat, 2009-02-14 at 07:45 -0700, Linuxguy123 wrote: > Excuse my ignorance, but is there a limit to the size of function names > in Python ? > > I named a function getSynclientVersion() and I got an error when I > called it. You forgot to paste the error. -- http://mail.python.org/mailman/lis

Re: Function name limit in Python ?

2009-02-14 Thread Paul McGuire
> fine. > > Why ? > Hello again, Linuxguy123! I see you are forging ahead in your quest for Python knowledge. Here is a small snippet that refutes your assertion that function name length is a problem (but surely, you could have written this small a test and answered your own question...

Re: Function name limit in Python ?

2009-02-14 Thread MRAB
Linuxguy123 wrote: Excuse my ignorance, but is there a limit to the size of function names in Python ? I named a function getSynclientVersion() and I got an error when I called it. I renamed the same function to getSCVersion() and it called fine. Why ? Probably a just spelling mistake. Double

Function name limit in Python ?

2009-02-14 Thread Linuxguy123
Excuse my ignorance, but is there a limit to the size of function names in Python ? I named a function getSynclientVersion() and I got an error when I called it. I renamed the same function to getSCVersion() and it called fine. Why ? Thanks -- http://mail.python.org/mailman/listinfo/python-lis

Re: calling variable function name ?

2008-05-06 Thread Blais, Gerard C.
Sure! Make a dictionary: fdict = {"A":fa, "B":fb, ... } Then consider x = "A" result = fdict(x)(param1, param2) should call fa without any if's... Gerry -- http://mail.pytho

Re: calling variable function name ?

2008-05-02 Thread TkNeo
On Apr 30, 11:05 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > TkNeo<[EMAIL PROTECTED]> writes: > > > George - Thanks for your reply but what you suggested is not working: > > > def FA(param1,param2): > > print "FA" + param1 + " " + param2 > > def FA(param1,param2): > > print "FB" + par

Re: calling variable function name ?

2008-05-01 Thread Duncan Booth
"thinkofwhy" <[EMAIL PROTECTED]> wrote: > Try a dictionary: > > def funcA(blah, blah) > def funcB(blah, blah) > def funcC(blah, blah) > functions = {'A': funcA, 'B': funcB, 'C': > funcC} > user_func = 'A' > functions[user_func] #execute function Python has a neat concept

Re: calling variable function name ?

2008-04-30 Thread thinkofwhy
Try a dictionary: def funcA(blah, blah) def funcB(blah, blah) def funcC(blah, blah) functions = {'A': funcA, 'B': funcB, 'C': funcC} user_func = 'A' functions[user_func] #execute function "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] TkNeo

Re: calling variable function name ?

2008-04-30 Thread Arnaud Delobelle
TkNeo <[EMAIL PROTECTED]> writes: > > George - Thanks for your reply but what you suggested is not working: > > def FA(param1,param2): > print "FA" + param1 + " " + param2 > def FA(param1,param2): > print "FB" + param1 + " " + param2 > def FA(param1,param2): > print "FC" + param1 + " "

Re: calling variable function name ?

2008-04-30 Thread TkNeo
On Apr 8, 7:51 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On Apr 8, 3:52 pm,TkNeo<[EMAIL PROTECTED]> wrote: > > > I don't know the exact terminology in python, but this is something i > > am trying to do > > > i have 3 functions lets say > > FA(param1,param2) > > FB(param1,param2) > > FC(param1

  1   2   >