Re: Functions as Enum member values

2021-05-31 Thread Colin McPhail via Python-list
> On 31 May 2021, at 18:24, Peter Otten <__pete...@web.de> wrote: > > On 31/05/2021 17:57, Colin McPhail via Python-list wrote: >> Hi, >> According to the enum module's documentation an Enum-based enumeration's >> members can have values of any type: >> "Member values can be anything: int

Re: Functions as Enum member values

2021-05-31 Thread Peter Otten
On 31/05/2021 17:57, Colin McPhail via Python-list wrote: Hi, According to the enum module's documentation an Enum-based enumeration's members can have values of any type: "Member values can be anything: int, str, etc.." You didn't read the fineprint ;) """ The rules for what is all

Re: functions vs methods

2018-07-22 Thread Chris Angelico
On Mon, Jul 23, 2018 at 1:49 AM, MRAB wrote: > On 2018-07-22 10:08, Ben Finney wrote: >> >> INADA Naoki writes: >> >>> Please don't refer the FAQ entry. >>> See this: https://bugs.python.org/issue27671 >> >> >> Interesting. Thanks for raising that bug report. >> >> I offer my text as a starting p

Re: functions vs methods

2018-07-22 Thread MRAB
On 2018-07-22 10:08, Ben Finney wrote: INADA Naoki writes: Please don't refer the FAQ entry. See this: https://bugs.python.org/issue27671 Interesting. Thanks for raising that bug report. I offer my text as a starting point for a better explanation: Because ‘len’ works with *any* seque

Re: functions vs methods

2018-07-22 Thread Ben Finney
INADA Naoki writes: > Please don't refer the FAQ entry. > See this: https://bugs.python.org/issue27671 Interesting. Thanks for raising that bug report. I offer my text as a starting point for a better explanation: Because ‘len’ works with *any* sequence, not only lists. To implement it

Re: functions vs methods

2018-07-22 Thread INADA Naoki
> > Your particular question is itself a FAQ > https://docs.python.org/3/faq/design.html#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list>. > Please don't refer the FAQ entry. See this: https://bugs.python.org/issue27671 -- INADA Naoki --

Re: functions vs methods

2018-07-22 Thread Sharan Basappa
On Sunday, 22 July 2018 13:32:16 UTC+5:30, Ben Finney wrote: > Sharan Basappa writes: > > > Is there a difference between functions and methods in Python. > > Python's documentation includes a useful Glossary. See the terms > https://docs.python.org/3/glossary.html#term-method> > https://docs.p

Re: functions vs methods

2018-07-22 Thread Ben Finney
Sharan Basappa writes: > Is there a difference between functions and methods in Python. Python's documentation includes a useful Glossary. See the terms https://docs.python.org/3/glossary.html#term-method> https://docs.python.org/3/glossary.html#term-function>. Every method is a function; but t

Re: functions vs methods

2018-07-21 Thread dieter
Sharan Basappa writes: > Is there a difference between functions and methods in Python. Somewhat simplified: a method is a function with the method's associated object implicitly passed as first argument. For a Python defined method "m", you can get the corresponding function via "m.__func__" (

Re: functions vs methods

2018-07-21 Thread Sharan Basappa
Thanks a lot. On Sunday, 22 July 2018 04:02:23 UTC+5:30, Rick Johnson wrote: > On Saturday, July 21, 2018 at 2:06:21 PM UTC-5, Sharan Basappa wrote: > > Is there a difference between functions and methods in Python. > > Generally speaking, functions and methods are basically two > words describi

Re: functions vs methods

2018-07-21 Thread Lele Gaifax
Sharan Basappa writes: > Refer to the following lines: > 1) len(list) > 2) list.append() > > In the first case, len is a function that python provides to which list can > be passed and in the second case, append is a method within list class? > > If my interpretation is correct, why not make le

Re: Functions unnecessarily called in Python/pylifecycle.c:_Py_InitializeCore() ?

2018-03-01 Thread Thomas Nyberg
On 03/01/2018 04:58 PM, Ned Batchelder wrote: > This sounds like it could make a good contribution to CPython :) > > --Ned. Thanks for the recommendation. Issue/PR created: https://bugs.python.org/issue32980 https://github.com/python/cpython/pull/5953 Cheers, Thomas -- https://

Re: Functions unnecessarily called in Python/pylifecycle.c:_Py_InitializeCore() ?

2018-03-01 Thread Ned Batchelder
On 3/1/18 7:40 AM, Thomas Nyberg wrote: On 03/01/2018 12:46 PM, bartc wrote: If they're only called once, then it probably doesn't matter too much in terms of harming performance. Oh yeah there's no way this has any affect on performance. A smart compiler might even be able optimize the call aw

Re: Functions unnecessarily called in Python/pylifecycle.c:_Py_InitializeCore() ?

2018-03-01 Thread Thomas Nyberg
On 03/01/2018 12:46 PM, bartc wrote: > If they're only called once, then it probably doesn't matter too much in > terms of harming performance. Oh yeah there's no way this has any affect on performance. A smart compiler might even be able optimize the call away entirely. Even if it couldn't, it's

Re: Functions unnecessarily called in Python/pylifecycle.c:_Py_InitializeCore() ?

2018-03-01 Thread bartc
On 01/03/2018 09:57, Thomas Nyberg wrote: Hello, I was playing around with cpython and noticed the following. The `_PyFrame_Init()` and `PyByteArray_Init()` functions are called in these two locations: https://github.com/python/cpython/blob/master/Python/pylifecycle.c#L693-L694

Re: Functions Of Functions Returning Functions

2016-09-19 Thread Lawrence D’Oliveiro
On Monday, September 19, 2016 at 6:54:31 PM UTC+12, dieter wrote: > Some time ago, we had a (quite heated) discussion here ... I have noticed that people get very defensive about things they don’t understand. > Often, functions returning functions are more difficult to understand > than "first o

Re: Functions Of Functions Returning Functions

2016-09-18 Thread dieter
Lawrence D’Oliveiro writes: > The less code you have to write, the better. Less code means less > maintenance, and fewer opportunities for bugs. While I agree with you in general, sometimes less code can be harder to maintain (when it is more difficult to understand). Some time ago, we had a (qu

Re: Functions Of Functions Returning Functions

2016-09-18 Thread Steve D'Aprano
On Sun, 18 Sep 2016 08:28 pm, Lawrence D’Oliveiro wrote: > This shows the power of functions as first-class objects. The concept > is older than object orientation, and is often left out of > object-oriented languages. I think Python benefits from the fact that > it had functions before it had cla

Re: functions, optional parameters

2015-05-10 Thread Chris Angelico
On Sun, May 10, 2015 at 9:25 PM, Dave Angel wrote: > On 05/09/2015 11:33 PM, Chris Angelico wrote: >> What you could have is "late-binding semantics, optional early binding >> as an optimization but only in cases where the result is >> indistinguishable". That would allow common cases (int/bool/st

Re: functions, optional parameters

2015-05-10 Thread Dave Angel
On 05/09/2015 11:33 PM, Chris Angelico wrote: On Sun, May 10, 2015 at 12:45 PM, Steven D'Aprano wrote: This is the point where some people try to suggest some sort of complicated, fragile, DWIM heuristic where the compiler tries to guess whether the user actually wants the default to use early

Re: functions, optional parameters

2015-05-10 Thread Chris Angelico
(To clarify, I am *not* talking about this as a change to Python, so all questions of backward compatibility are immaterial. This is "what happens if we go back in time and have Python use late binding semantics". This is the "alternate 1985" of Back to the Future.) On Sun, May 10, 2015 at 3:20 PM

Re: functions, optional parameters

2015-05-09 Thread Steven D'Aprano
On Sun, 10 May 2015 01:35 pm, Rustom Mody wrote: > On Sunday, May 10, 2015 at 8:16:07 AM UTC+5:30, Steven D'Aprano wrote: >> I predict that the majority of the time, late binding would just be a >> pointless waste of time: >> >> def process_string(thestr, start=0, end=None, slice=1, reverse=True)

Re: functions, optional parameters

2015-05-09 Thread Steven D'Aprano
On Sun, 10 May 2015 01:33 pm, Chris Angelico wrote: > On Sun, May 10, 2015 at 12:45 PM, Steven D'Aprano > wrote: >> This is the point where some people try to suggest some sort of >> complicated, fragile, DWIM heuristic where the compiler tries to guess >> whether the user actually wants the defa

Re: functions, optional parameters

2015-05-09 Thread Rustom Mody
On Sunday, May 10, 2015 at 8:16:07 AM UTC+5:30, Steven D'Aprano wrote: > I predict that the majority of the time, late binding would just be a > pointless waste of time: > > def process_string(thestr, start=0, end=None, slice=1, reverse=True): > pass > > Why would you want 0, None, 1 and True

Re: functions, optional parameters

2015-05-09 Thread Chris Angelico
On Sun, May 10, 2015 at 12:45 PM, Steven D'Aprano wrote: > This is the point where some people try to suggest some sort of complicated, > fragile, DWIM heuristic where the compiler tries to guess whether the user > actually wants the default to use early or late binding, based on what the > expres

Re: functions, optional parameters

2015-05-09 Thread Steven D'Aprano
On Sat, 9 May 2015 01:50 am, Michael Welle wrote: [...] >> How about this definition: >> >> default = 23 >> def spam(eggs=default): >> pass >> >> del default >> >> print spam() >> >> >> Do you expect the function call to fail because `default` doesn't exist? > > If I refer

Re: functions, optional parameters

2015-05-09 Thread Ian Kelly
On Fri, May 8, 2015 at 9:50 AM, Michael Welle wrote: > > Steven D'Aprano writes: >> >> If your language uses late binding, it is very inconvenient to get early >> binding when you want it. But if your language uses early binding, it is >> very simple to get late binding when you want it: just put

Re: functions, optional parameters

2015-05-09 Thread Gregory Ewing
Chris Angelico wrote: So no, it isn't proof - it's equally well explained by the code object being constant. I suppose, strictly speaking, that's true -- but then the code object *might as well* be created at compile time, since the semantics are identical. In any case, it's easy to see from

Re: functions, optional parameters

2015-05-08 Thread Steven D'Aprano
On Sat, 9 May 2015 03:49 am, Chris Angelico wrote: > On Sat, May 9, 2015 at 3:36 AM, Steven D'Aprano > wrote: >> On Sat, 9 May 2015 02:02 am, Chris Angelico wrote: >>> Aside from constructing two closures in the same context and proving >>> that their __code__ attributes point to the same object,

Re: functions, optional parameters

2015-05-08 Thread Chris Angelico
On Sat, May 9, 2015 at 11:41 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> How do you know that the function's code >> object was created when compile() happened, rather than being created >> when the function was defined? > > > Python 3.4.2 (default, Feb 4 2015, 20:08:25) > [GCC 4.2.1 (

Re: functions, optional parameters

2015-05-08 Thread Gregory Ewing
Chris Angelico wrote: How do you know that the function's code object was created when compile() happened, rather than being created when the function was defined? Python 3.4.2 (default, Feb 4 2015, 20:08:25) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or

Re: functions, optional parameters

2015-05-08 Thread Mel Wilson
On Sat, 09 May 2015 03:49:36 +1000, Chris Angelico wrote: > Yes, but can you *distinguish* them in terms of default argument versus > code object creation? How do you know that the function's code object > was created when compile() happened, rather than being created when the > function was defin

Re: functions, optional parameters

2015-05-08 Thread Chris Angelico
On Sat, May 9, 2015 at 3:36 AM, Steven D'Aprano wrote: > On Sat, 9 May 2015 02:02 am, Chris Angelico wrote: >> Aside from constructing two closures in the same context and proving >> that their __code__ attributes point to the same object, is there any >> way to distinguish between "code object co

Re: functions, optional parameters

2015-05-08 Thread Steven D'Aprano
On Sat, 9 May 2015 02:02 am, Chris Angelico wrote: > On Sat, May 9, 2015 at 1:48 AM, Ian Kelly wrote: >> On May 8, 2015 9:26 AM, "Steven D'Aprano" >> wrote: >>> >>> Do you think that Python will re-compile the body of the function every >>> time >>> you call it? Setting the default is part of th

Re: functions, optional parameters

2015-05-08 Thread Steven D'Aprano
On Sat, 9 May 2015 01:48 am, Ian Kelly wrote: > On May 8, 2015 9:26 AM, "Steven D'Aprano" < > steve+comp.lang.pyt...@pearwood.info> wrote: >> >> Do you think that Python will re-compile the body of the function every > time >> you call it? Setting the default is part of the process of compiling th

Re: functions, optional parameters

2015-05-08 Thread Chris Angelico
On Sat, May 9, 2015 at 1:48 AM, Ian Kelly wrote: > On May 8, 2015 9:26 AM, "Steven D'Aprano" > wrote: >> >> Do you think that Python will re-compile the body of the function every >> time >> you call it? Setting the default is part of the process of compiling the >> function. > > To be a bit peda

Re: functions, optional parameters

2015-05-08 Thread Ian Kelly
On May 8, 2015 9:26 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > > Do you think that Python will re-compile the body of the function every time > you call it? Setting the default is part of the process of compiling the > function. To be a bit pedantic, that's not accurate

Re: functions, optional parameters

2015-05-08 Thread Steven D'Aprano
On Fri, 8 May 2015 09:59 pm, Michael Welle wrote: > Hello, > > assume the following function definition: > > def bar(foo = []): > print("foo: %s" % foo) > foo.append("foo") > > It doesn't work like one would expect (or as I would expect ;-)). As I > understand it the assignment of the e

Re: functions, optional parameters

2015-05-08 Thread Chris Angelico
On Fri, May 8, 2015 at 9:59 PM, Michael Welle wrote: > Hello, > > assume the following function definition: > > def bar(foo = []): > print("foo: %s" % foo) > foo.append("foo") > > It doesn't work like one would expect (or as I would expect ;-)). As I > understand it the assignment of the e

Re: functions, optional parameters

2015-05-08 Thread Rustom Mody
On Friday, May 8, 2015 at 5:30:15 PM UTC+5:30, Michael Welle wrote: > Hello, > > assume the following function definition: > > def bar(foo = []): > print("foo: %s" % foo) > foo.append("foo") > > It doesn't work like one would expect (or as I would expect ;-)). As I > understand it the as

Re: Functions on list items

2014-08-19 Thread Kurt
> > Maybe http://pandas.pydata.org/ ??? > > Thanks. This reply is like that butterfly wing flap causing hurricanes a world away; big steerage away from proprietary stuff used in my org. Detox will take some time though. K -- https://mail.python.org/mailman/listinfo/python-list

Re: Functions on list items

2014-08-19 Thread Tim Chase
On 2014-08-19 10:34, Kurt wrote: > I am trying to process the following calendar and data attributes > in a file: Da Mo Yr AttrA AttrB AttrC... > I need to average AttrA for each of 365 Da days across Yr years. > Then do the same for 27K files. Repeat for AttrB, AttrC etc. Can I > do the averaging

Re: Functions on list items

2014-08-19 Thread Mark Lawrence
On 19/08/2014 18:34, Kurt wrote: I am trying to process the following calendar and data attributes in a file: Da Mo Yr AttrA AttrB AttrC... I need to average AttrA for each of 365 Da days across Yr years. Then do the same for 27K files. Repeat for AttrB, AttrC etc. Can I do the averaging with li

Re: Functions help

2014-03-01 Thread Grant Edwards
On 2014-02-24, Benjamin Kaplan wrote: > On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: >> On 24/02/2014 11:09 AM, Mark Lawrence wrote: >>> >>> On 24/02/2014 00:55, alex23 wrote: for _ in range(5): func() >>> >>> >>> the obvious indentation error above >> >> >> Stupid

Re: Functions help

2014-03-01 Thread Roy Smith
In article , Mark Lawrence wrote: > On 24/02/2014 00:55, alex23 wrote: > > On 23/02/2014 3:43 PM, Scott W Dunning wrote: > >> I had a question regarding functions. Is there a way to call a > >> function multiple times without recalling it over and over. Meaning > >> is there a way I can call a

Re: Functions help

2014-02-27 Thread Rhodri James
On Tue, 25 Feb 2014 02:18:43 -, Dennis Lee Bieber wrote: On Mon, 24 Feb 2014 01:01:15 -, "Rhodri James" declaimed the following: The function "range" returns the sequence of numbers 1, 2, 3, 4 and 5 [*], so this has the same effect as if you had typed: Wrong -- it

Re: Functions help

2014-02-26 Thread rurpy
On 02/25/2014 07:52 PM, Ethan Furman wrote: > On 02/23/2014 08:01 PM, ru...@yahoo.com wrote: >> On 02/23/2014 08:21 PM, Mark Lawrence wrote: >>> On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: > On 24/02/2014 11:09 AM, Mark Lawrence wrote: >>

Re: Functions help

2014-02-26 Thread Mark Lawrence
On 26/02/2014 02:06, Cameron Simpson wrote: On 24Feb2014 13:59, Mark Lawrence wrote: On 24/02/2014 04:01, ru...@yahoo.com wrote: On 02/23/2014 08:21 PM, Mark Lawrence wrote: On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: On 24/02/2014 11:09 AM, M

Re: Functions help

2014-02-25 Thread Ethan Furman
On 02/23/2014 08:01 PM, ru...@yahoo.com wrote: On 02/23/2014 08:21 PM, Mark Lawrence wrote: On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: On 24/02/2014 11:09 AM, Mark Lawrence wrote: On 24/02/2014 00:55, alex23 wrote: for _ in range(5):

Re: Functions help

2014-02-25 Thread Cameron Simpson
On 23Feb2014 18:55, Benjamin Kaplan wrote: > On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: > > On 24/02/2014 11:09 AM, Mark Lawrence wrote: > >> On 24/02/2014 00:55, alex23 wrote: > >>> for _ in range(5): > >>> func() > >> > >> the obvious indentation error above > > > > Stupid cut&pas

Re: Functions help

2014-02-25 Thread Cameron Simpson
On 24Feb2014 13:59, Mark Lawrence wrote: > On 24/02/2014 04:01, ru...@yahoo.com wrote: > >On 02/23/2014 08:21 PM, Mark Lawrence wrote: > >>On 24/02/2014 02:55, Benjamin Kaplan wrote: > >>>On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: > On 24/02/2014 11:09 AM, Mark Lawrence wrote: > >On 2

Re: Functions help

2014-02-24 Thread Jean-Michel Pichavant
- Original Message - > On Feb 23, 2014, at 1:44 AM, Steven D'Aprano < > steve+comp.lang.pyt...@pearwood.info > wrote: > > Sorry, I don't really understand your question. Could you show an > > example > > > of what you are doing? > > > Do you mean "add 5" or "*5"? "Add *5 doesn't really

Re: Functions help

2014-02-24 Thread Mark Lawrence
On 24/02/2014 04:01, ru...@yahoo.com wrote: On 02/23/2014 08:21 PM, Mark Lawrence wrote: On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: On 24/02/2014 11:09 AM, Mark Lawrence wrote: On 24/02/2014 00:55, alex23 wrote: for _ in range(5):

Re: Functions help

2014-02-24 Thread sffjunkie
On Sunday, 23 February 2014 05:43:17 UTC, Scott W Dunning wrote: > I had a question regarding functions. Is there a way to call a function > multiple times without recalling it over and over. Meaning is there a way I > can call a function and then add *5 or something like that? The followin

Re: Functions help

2014-02-24 Thread sffjunkie
On Sunday, 23 February 2014 05:43:17 UTC, Scott W Dunning wrote: > I had a question regarding functions. Is there a way to call a function > multiple times without recalling it over and over. Meaning is there a way I > can call a function and then add *5 or something like that? > The followi

Re: Functions help

2014-02-23 Thread rurpy
On 02/23/2014 08:21 PM, Mark Lawrence wrote: > On 24/02/2014 02:55, Benjamin Kaplan wrote: >> On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: >>> On 24/02/2014 11:09 AM, Mark Lawrence wrote: On 24/02/2014 00:55, alex23 wrote: > for _ in range(5): > func() the obvious i

Re: Functions help

2014-02-23 Thread MRAB
On 2014-02-24 03:21, Mark Lawrence wrote: On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: On 24/02/2014 11:09 AM, Mark Lawrence wrote: On 24/02/2014 00:55, alex23 wrote: for _ in range(5): func() the obvious indentation error above

Re: Functions help

2014-02-23 Thread Mark Lawrence
On 24/02/2014 02:55, Benjamin Kaplan wrote: On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: On 24/02/2014 11:09 AM, Mark Lawrence wrote: On 24/02/2014 00:55, alex23 wrote: for _ in range(5): func() the obvious indentation error above Stupid cut&paste :( -- Your message c

Re: Functions help

2014-02-23 Thread Benjamin Kaplan
On Sun, Feb 23, 2014 at 5:39 PM, alex23 wrote: > On 24/02/2014 11:09 AM, Mark Lawrence wrote: >> >> On 24/02/2014 00:55, alex23 wrote: >>> >>> >>> for _ in range(5): >>> func() >> >> >> the obvious indentation error above > > > Stupid cut&paste :( > -- Your message came through fine for

Re: Functions help

2014-02-23 Thread Scott W Dunning
I understood what you meant because I looked up loops in the python documentation since we haven’t got there yet in school. On Feb 23, 2014, at 6:39 PM, alex23 wrote: > On 24/02/2014 11:09 AM, Mark Lawrence wrote: >> On 24/02/2014 00:55, alex23 wrote: >>> >>> for _ in range(5): >>> f

Re: Functions help

2014-02-23 Thread Scott W Dunning
On Feb 23, 2014, at 12:59 AM, Ben Finney wrote: > > You should ask question like this on the “python-tutor” forum. Thanks Ben, I wasn’t aware of PythonTutor. -- https://mail.python.org/mailman/listinfo/python-list

Re: Functions help

2014-02-23 Thread alex23
On 24/02/2014 11:09 AM, Mark Lawrence wrote: On 24/02/2014 00:55, alex23 wrote: for _ in range(5): func() the obvious indentation error above Stupid cut&paste :( -- https://mail.python.org/mailman/listinfo/python-list

Re: Functions help

2014-02-23 Thread Travis Griggs
> On Feb 23, 2014, at 17:09, Mark Lawrence wrote: > > For the benefit of newbies, besides the obvious indentation error above, the > underscore basically acts as a dummy variable. I'll let the language lawyers > give a very detailed, precise description :) You mean a dummy name binding, rig

Re: Functions help

2014-02-23 Thread Scott W Dunning
On Feb 23, 2014, at 1:44 AM, Steven D'Aprano wrote: > > Sorry, I don't really understand your question. Could you show an example > of what you are doing? > > Do you mean "add 5" or "*5"? "Add *5 doesn't really mean anything to me. Sorry I forgot to add the code that I had to give an example

Re: Functions help

2014-02-23 Thread Mark Lawrence
On 24/02/2014 00:55, alex23 wrote: On 23/02/2014 3:43 PM, Scott W Dunning wrote: I had a question regarding functions. Is there a way to call a function multiple times without recalling it over and over. Meaning is there a way I can call a function and then add *5 or something like that? The

Re: Functions help

2014-02-23 Thread Rhodri James
On Sun, 23 Feb 2014 05:43:17 -, Scott W Dunning wrote: I had a question regarding functions. Is there a way to call a function multiple times without recalling it over and over. Meaning is there a way I can call a function and then add *5 or something like that? The usual way to ca

Re: Functions help

2014-02-23 Thread alex23
On 23/02/2014 3:43 PM, Scott W Dunning wrote: I had a question regarding functions. Is there a way to call a function multiple times without recalling it over and over. Meaning is there a way I can call a function and then add *5 or something like that? The same way you repeat anything in P

Re: Functions help

2014-02-23 Thread Steven D'Aprano
On Sat, 22 Feb 2014 22:43:17 -0700, Scott W Dunning wrote: > Hello, > > I had a question regarding functions. Is there a way to call a function > multiple times without recalling it over and over. Meaning is there a > way I can call a function and then add *5 or something like that? Sorry, I

Re: Functions help

2014-02-23 Thread Ben Finney
Scott W Dunning writes: > I had a question regarding functions. Is there a way to call a > function multiple times without recalling it over and over. You should ask question like this on the “python-tutor” forum. I say that because this question suggests you have yet to learn about basic Pytho

Re: functions which take functions

2012-04-13 Thread Antti "Andy" Ylikoski
12.4.2012 18:48, Kiuhnm kirjoitti: On 4/11/2012 16:01, Antti J Ylikoski wrote: On 9.4.2012 21:57, Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Thank you. Kiuhnm A f

Re: functions which take functions

2012-04-12 Thread Kiuhnm
On 4/12/2012 19:29, Jan Kuiken wrote: On 4/9/12 20:57 , Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? I don't use it daily but the first argument of list.sort, i.e. t

Re: functions which take functions

2012-04-12 Thread Jan Kuiken
On 4/9/12 20:57 , Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? I don't use it daily but the first argument of list.sort, i.e. the compare function springs to mind. J

Re: functions which take functions

2012-04-12 Thread Kiuhnm
On 4/12/2012 8:07, Tim Roberts wrote: Kiuhnm wrote: That won't do. A good example is when you pass a function to re.sub, for instance. This is an odd request. All shall be revealed :) I often pass functions to functions in order to simulate a C switch statement, such as in a language tr

Re: functions which take functions

2012-04-12 Thread Kiuhnm
On 4/11/2012 16:01, Antti J Ylikoski wrote: On 9.4.2012 21:57, Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Thank you. Kiuhnm A function to numerically integrate ano

Re: functions which take functions

2012-04-11 Thread Tim Roberts
Kiuhnm wrote: > >That won't do. A good example is when you pass a function to re.sub, for >instance. This is an odd request. I often pass functions to functions in order to simulate a C switch statement, such as in a language translator: commands = { 'add': doAdd, 'subtract' : doSubt

Re: functions which take functions

2012-04-11 Thread Tim Chase
On 04/10/12 08:36, Kiuhnm wrote: On 4/10/2012 14:29, Ulrich Eckhardt wrote: Am 09.04.2012 20:57, schrieb Kiuhnm: That won't do. A good example is when you pass a function to re.sub, for instance. If that's a good example, then why not use it? I've used it on multiple occasions to do lookups

Re: functions which take functions

2012-04-11 Thread Antti J Ylikoski
On 9.4.2012 21:57, Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Thank you. Kiuhnm A function to numerically integrate another function comes as follows:

Re: functions which take functions

2012-04-11 Thread Dave Angel
On 04/11/2012 06:55 AM, Kiuhnm wrote: > On 4/10/2012 23:43, Eelco wrote: >> On Apr 10, 3:36 am, Kiuhnm wrote: >>> On 4/10/2012 14:29, Ulrich Eckhardt wrote: >>> Am 09.04.2012 20:57, schrieb Kiuhnm: > Do you have some real or realistic (but easy and self-contained) > examples when you

Re: functions which take functions

2012-04-11 Thread Kiuhnm
On 4/10/2012 23:43, Eelco wrote: On Apr 10, 3:36 am, Kiuhnm wrote: On 4/10/2012 14:29, Ulrich Eckhardt wrote: Am 09.04.2012 20:57, schrieb Kiuhnm: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to anot

Re: functions which take functions

2012-04-10 Thread Chris Angelico
On Tue, Apr 10, 2012 at 11:36 PM, Kiuhnm wrote: > On 4/10/2012 14:29, Ulrich Eckhardt wrote: >> >> Am 09.04.2012 20:57, schrieb Kiuhnm: >>> >>> Do you have some real or realistic (but easy and self-contained) >>> examples when you had to define a (multi-statement) function and pass it >>> to anoth

Re: functions which take functions

2012-04-10 Thread Eelco
On Apr 10, 3:36 am, Kiuhnm wrote: > On 4/10/2012 14:29, Ulrich Eckhardt wrote: > > > Am 09.04.2012 20:57, schrieb Kiuhnm: > >> Do you have some real or realistic (but easy and self-contained) > >> examples when you had to define a (multi-statement) function and pass it > >> to another function? >

Re: functions which take functions

2012-04-10 Thread Kiuhnm
On 4/10/2012 14:29, Ulrich Eckhardt wrote: Am 09.04.2012 20:57, schrieb Kiuhnm: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? Take a look at decorators, they not only take non-trivi

Re: functions which take functions

2012-04-10 Thread Ulrich Eckhardt
Am 09.04.2012 20:57, schrieb Kiuhnm: > Do you have some real or realistic (but easy and self-contained) > examples when you had to define a (multi-statement) function and pass it > to another function? Take a look at decorators, they not only take non-trivial functions but also return them. That s

Re: functions which take functions

2012-04-09 Thread Emile van Sebille
On 4/9/2012 11:57 AM Kiuhnm said... Do you have some real or realistic ... yes (but easy and self-contained) aah, no. examples when you had to define a (multi-statement) function and pass it to another function? This weekend I added functionality to a subsystem that allows users to

Re: functions which take functions

2012-04-09 Thread Terry Reedy
On 4/9/2012 2:57 PM, Kiuhnm wrote: Do you have some real or realistic (but easy and self-contained) examples when you had to define a (multi-statement) function and pass it to another function? This is so common in Python that it is hardly worth sneezing about. map(f, iterable) filter(f, itera

Re: Functions vs OOP

2011-09-05 Thread William Gill
On 9/5/2011 3:04 PM, Jean-Michel Pichavant wrote: William Gill wrote: Not to split hairs, but syntactically f(x) is a function in many programming paradigms. As I understand it functional programming places specific requirements on functions, i.e.referential transparency. So f(x) may or may no

Re: Functions vs OOP

2011-09-05 Thread Terry Reedy
On 9/5/2011 1:45 PM, William Gill wrote: On 9/4/2011 9:13 AM, rusi wrote: On Sep 3, 9:15 pm, William Gill wrote: During some recent research, and re-familiarization with Python, I came across documentation that suggests that programming using functions, and programming using objects were someho

Re: Functions vs OOP

2011-09-05 Thread Jean-Michel Pichavant
William Gill wrote: Not to split hairs, but syntactically f(x) is a function in many programming paradigms. As I understand it functional programming places specific requirements on functions, i.e.referential transparency. So f(x) may or may not be "functional". x.f() is also a function,

Re: Functions vs OOP

2011-09-05 Thread William Gill
On 9/3/2011 12:25 PM, Steven D'Aprano wrote: William Gill wrote: Are they suggesting that any function that takes an object as an argument should always be a method of that object? Yes. I can think of times when a special application, such as a converter, would take an object as an argumen

Re: Functions vs OOP

2011-09-05 Thread William Gill
On 9/4/2011 9:13 AM, rusi wrote: On Sep 3, 9:15 pm, William Gill wrote: During some recent research, and re-familiarization with Python, I came across documentation that suggests that programming using functions, and programming using objects were somehow opposing techniques. Staying with (fo

Re: Functions vs OOP

2011-09-04 Thread Chris Angelico
On Mon, Sep 5, 2011 at 9:41 AM, Steven D'Aprano wrote: > http://docs.python.org/dev/howto/functional.html > > What about the entire "Introduction" section, which starts with this > statement? > > "This section explains the basic concept of functional programming" > > If you would like to suggest i

Re: Functions vs OOP

2011-09-04 Thread William Gill
On 9/4/2011 7:41 PM, Steven D'Aprano wrote: William Gill wrote: The source of my error is "Functional Programming HOWTO (/python-3.1.3-docs-html/howto/functional.html)" For those who don't have access to William's local file system, I expect he's looking at this: http://docs.python.org/relea

Re: Functions vs OOP

2011-09-04 Thread Steven D'Aprano
William Gill wrote: > The source of my error is "Functional Programming HOWTO > (/python-3.1.3-docs-html/howto/functional.html)" For those who don't have access to William's local file system, I expect he's looking at this: http://docs.python.org/release/3.1.3/howto/functional.html or the most

Re: Functions vs OOP

2011-09-04 Thread William Gill
On 9/4/2011 2:32 PM, Terry Reedy wrote: On 9/4/2011 4:13 AM, tinn...@isbd.co.uk wrote: Ian Kelly wrote: Functional programming is about using functions in the *mathematical* sense. A mathematical function maps one value (or tuple of values) to another value. The mapped value never varies; if

Re: Functions vs OOP

2011-09-04 Thread Terry Reedy
On 9/4/2011 4:13 AM, tinn...@isbd.co.uk wrote: Ian Kelly wrote: Functional programming is about using functions in the *mathematical* sense. A mathematical function maps one value (or tuple of values) to another value. The mapped value never varies; if it did, it would be a different functi

Re: Functions vs OOP

2011-09-04 Thread rusi
On Sep 3, 9:15 pm, William Gill wrote: > During some recent research, and re-familiarization with Python, I came > across documentation that suggests that programming using functions, and > programming using objects were somehow opposing techniques. Staying with (for the moment) the suggestion th

Re: Functions vs OOP

2011-09-04 Thread Steven D'Aprano
tinn...@isbd.co.uk wrote: > I think there may be another issue here. If someone says "functional > programming" to me then I would generally assume that they *do* mean > "programming using functions". Strictly speaking you are correct, "functional programming" does mean "programming using func

Re: Functions vs OOP

2011-09-04 Thread Adam Jorgensen
Progranming with functions vs Progranming with objects sounds like C vs. C++ more than functional programming vs. OO programming On 4 September 2011 04:18, William Gill wrote: > On 9/3/2011 9:51 PM, Terry Reedy wrote: > >> >> It is possible that our doc was less than crystal clear. We are >> con

Re: Functions vs OOP

2011-09-04 Thread tinnews
Ian Kelly wrote: > On Sat, Sep 3, 2011 at 10:15 AM, William Gill wrote: > > During some recent research, and re-familiarization with Python, I came > > across documentation that suggests that programming using functions, and > > programming using objects were somehow opposing techniques. > > > >

Re: Functions vs OOP

2011-09-03 Thread William Gill
On 9/3/2011 9:51 PM, Terry Reedy wrote: It is possible that our doc was less than crystal clear. We are constantly improving it where we can see fixable faults. If you run across whatever it was and it still seems a bit muddy, post something again. Will do. Thanks. -- http://mail.python.org/m

  1   2   3   >