George Fischhof writes:
> George Fischhof ezt írta (időpont: 2021. aug. 29., V,
> 21:27):
>
>>
>>
>> Loris Bennett ezt írta (időpont: 2021. aug.
>> 26., Cs, 16:02):
>>
>>> George Fischhof writes:
>>>
>>> [snip (79 lines)]
>>>
>>> >> > Hi,
>>> >> >
>>> >> > Also you can give a try to click and
George Fischhof ezt írta (időpont: 2021. aug. 29., V,
21:27):
>
>
> Loris Bennett ezt írta (időpont: 2021. aug.
> 26., Cs, 16:02):
>
>> George Fischhof writes:
>>
>> [snip (79 lines)]
>>
>> >> > Hi,
>> >> >
>> >> > Also you can give a try to click and / or typer packages.
>> >> > Putting args
Loris Bennett ezt írta (időpont: 2021. aug.
26., Cs, 16:02):
> George Fischhof writes:
>
> [snip (79 lines)]
>
> >> > Hi,
> >> >
> >> > Also you can give a try to click and / or typer packages.
> >> > Putting args into environment variables can be a solution too
> >> > All of these depends on s
George Fischhof writes:
[snip (79 lines)]
>> > Hi,
>> >
>> > Also you can give a try to click and / or typer packages.
>> > Putting args into environment variables can be a solution too
>> > All of these depends on several things: personal preferences, colleagues
>> /
>> > firm standards, the p
ing at in order to produce "sub-objects"?
> >>
> >> >> I guess I am really asking how to avoid "passing through" arguments
> to
> >> >> functions which only need them to call other functions, so maybe the
> >> >> answer is just t
>>
>> >> I guess I am really asking how to avoid "passing through" arguments to
>> >> functions which only need them to call other functions, so maybe the
>> >> answer is just to avoid nesting.
>> >
>> > No, you don't
.
> >
> > No, you don't get rid of code structure just not to pass arguments to
> > a function... Code may be poorly structured, but that's another
> > story.
>
> As I am writing new code it is more a question of imposing structure,
> rather than getting ri
Hi,
TL;DR:
If I have a command-line argument for a program, what is the best way
of making this available to a deeply-nested[1] function call without
passing the parameter through every intermediate function?
Long version:
If I have, say, a command-line program to send an email with a
personali
oid nesting.
>
> No, you don't get rid of code structure just not to pass arguments to
> a function... Code may be poorly structured, but that's another
> story.
As I am writing new code it is more a question of imposing structure,
rather than getting rid of structure. Unwri
assign
> to the variable in the outer function though.
>
> def a():
> value = None
> def b():
> nonlocal value
> value = 100
> return b
>
> You can do this through any number of levels of nested functions.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
https://mail.python.org/mailman/listinfo/python-list
in tcl.. Is it possible in Python too?
It is. What you have is a "nonlocal" variable. You will need to assign
to the variable in the outer function though.
def a():
value = None
def b():
nonlocal value
value = 100
return b
You can do this through any number o
def a() :
Print (value)
def b() :
Value = 100
Return b
Its a nested function. How can I use variable value just one function
above the parent function.
This is possible in tcl.. Is it possible in Python too?
--
https://mail.python.org/mailman/listinfo/python-list
nce.
>
>> 2. He's saying that within the 'call frame' (whatever that is)
>> there's an address to one of the previous stack frames of the wrapper
>> function ? What does all that mean in terms of nested functions?
>> Access link? How are nested fun
up?
Here you are no longer just talking about nested functions, you are talking
about closures. A stack is no longer sufficient for implementing closures.
The environment for the nested variables of the closure is often alloceted
on the heap.
--
Antoon Pardon.
--
https://mail.python.org/mailma
http://web.archive.org/web/20111030134120/http://www.sidhe.org/~dan/blog/archives/000211.html
(great tail recursion article - best i've seen! SO doesn't really
explain it unless you already knew it to begin with, but here's the
link:http://stackoverflow.com/questions/310974/what-is-tail-call-opti
er, the outer function may be
further up the stack. Since the outer function's local variables are
seen by the inner functions, the extra pointer is needed to access them
directly.
Python has nested functions. Thus, the same technique can be used to
implement Python's internal call sta
ated to one - CALL foo;
>
> 2. He's saying that within the 'call frame' (whatever that is) there's
> an address to one of the previous stack frames of the wrapper function
> ? What does all that mean in terms of nested functions? Access link?
> How are nested fu
ess to one of the previous stack frames of the wrapper function ?
What does all that mean in terms of nested functions? Access link? How
are nested function stacks setup..
3. What exactly is a traceback object - we know that an instance object
is a dictionary and some glue logic that allows
Adam Jorgensen wrote:
> Thanks :-) Sorry about the size, I wasn't sure what was relevant...
We prefer that you don't top-post here, because it makes it hard to see
context when people reply.
In general, people asking questions should always try to reduce the problem
to the simplest code that wil
Thanks :-) Sorry about the size, I wasn't sure what was relevant...
On 24 August 2011 15:29, Peter Otten <__pete...@web.de> wrote:
> Adam Jorgensen wrote:
>
>> Hi all, I'm experiencing a weird issue with closuring of parameters
>> and some nested function
Adam Jorgensen wrote:
> Hi all, I'm experiencing a weird issue with closuring of parameters
> and some nested functions I have inside two functions that
> return decorators. I think it's best illustrated with the actual code:
You should have made an effort to reduce its size
Hi all, I'm experiencing a weird issue with closuring of parameters
and some nested functions I have inside two functions that
return decorators. I think it's best illustrated with the actual code:
# This decorator doesn't work. For some reason python refuses to
closure the *decode
On Thu, 06 May 2010 12:40:16 +0200, Richard Lamboj wrote:
> Thank you for the nice sample, but what is with multiple inheritance in
> your sample? I mean the super call. Why not _MyClass.blah(self, arg).
super() should work correctly when you have more complicated multiple
inheritance, while cal
Richard Lamboj wrote:
>
>Thank you for the nice sample, but what is with multiple inheritance in your
>sample? I mean the super call. Why not _MyClass.blah(self, arg).
Because then I have to remember to change the name if I should happen to
change the base class, or copy this code into another c
Am Thursday 06 May 2010 12:02:47 schrieb Steven D'Aprano:
> On Thu, 06 May 2010 11:24:49 +0200, Richard Lamboj wrote:
> > Hello,
> >
> > what should i take:
> > - nested functions:
> > class MyClass(object)
> > def blah(self):
> >
On Thu, 06 May 2010 11:24:49 +0200, Richard Lamboj wrote:
> Hello,
>
> what should i take:
> - nested functions:
> class MyClass(object)
> def blah(self):
> def blub(var1, var2):
> do something...
> blub(1, 5)
The disadvantage of nested functions i
Hello,
what should i take:
- nested functions:
class MyClass(object)
def blah(self):
def blub(var1, var2):
do something...
blub(1, 5)
or
class MyClass(object)
def blah(self):
def _blub(var1, var2):
do something...
_blub(1, 5)
- "private" functi
Paul Hankin wrote:
I would decouple the speaker and the listener from the client, and
make the client interface more abstract. Simple and descriptive
interfaces can make code dramatically easier to understand.
class ClientListener(Thread):
def __init__(self, client, ...):
...
def ru
On Mar 20, 3:21 am, Esmail wrote:
> Hi,
>
> I'm new to writing Python code. This is a simple client I wrote, it
> works, but I feel it doesn't look as clean as it could. Can anyone
> make suggestions how to streamline this code?
>
> Also, I am using two nested
> To make a closure, the inner function *must* be nested in the outer.
> To be an instance method, a function *must* be a class attribute, and
> the easier way to indicate that is by nesting.
>
> In this case, the client does *not* use the other two classes, so the
> nesting is misleading. I thin
Esmail wrote:
In my opinion,
neither should be nested. Nothing is gained and something is lost.
Neither are used by client; indeed both use client.
I nested them because I see them as components of the client which
keeps track of the connection parameters and makes the initial
connection and
> make suggestions how to streamline this code?
>
> > Also, I am using two nested functions, it seems that nested functions
> > aren't used that much in Python - is that correct? And if so, how
> > come?
>
> > thanks,
>
> > Esmail
>
> > ps: I re
On Mar 19, 10:21 pm, Esmail wrote:
> Hi,
>
> I'm new to writing Python code. This is a simple client I wrote, it
> works, but I feel it doesn't look as clean as it could. Can anyone
> make suggestions how to streamline this code?
>
> Also, I am using two nested
Hi!
On Mar 20, 1:06 am, Terry Reedy wrote:
>
> What you wrote are two nested classes, not functions.
Ooops .. yes of course .. simple mistake (it was late .. :)
> In my opinion,
> neither should be nested. Nothing is gained and something is lost.
> Neither are used by client; indeed both use
Esmail wrote:
Hi,
I'm new to writing Python code. This is a simple client I wrote, it
works, but I feel it doesn't look as clean as it could. Can anyone
make suggestions how to streamline this code?
Also, I am using two nested functions, it seems that nested functions
aren't us
Hi,
I'm new to writing Python code. This is a simple client I wrote, it
works, but I feel it doesn't look as clean as it could. Can anyone
make suggestions how to streamline this code?
Also, I am using two nested functions, it seems that nested functions
aren't used that much in P
; pass
> > return resultToXml(locals()[action](*args))
>
> > def __task2(self, action, *args):
> > def request(params):
> > pass
> > def submit(params, values):
> > pass
> > def update(pa
I could use your callable approach, but like you said it may not be
worth the trouble.
The "trouble" I was talking about was not with using callable objects,
but with trying to hack func.func_code to extract nested functions (if
ever possible).
But anyway... The point of using cal
Bruno Desthuilliers wrote:
Gabriel Rossetti a écrit :
Terry Reedy wrote:
(snip)
Unlike the class approach, this requires recreating the constant
functions and dict with each call to _test. Quick to write but a
bit 'dirty', in my opinion. Another standard idiom is to set up the
constants ou
Gabriel Rossetti a écrit :
Terry Reedy wrote:
(snip)
Unlike the class approach, this requires recreating the constant
functions and dict with each call to _test. Quick to write but a bit
'dirty', in my opinion. Another standard idiom is to set up the
constants outside the function:
def re
Terry Reedy wrote:
Gabriel Rossetti wrote:
Bruno Desthuilliers wrote:
Gabriel Rossetti a écrit :
I thought that since functions are objects, that I could obtain
it's nested functions.
Well, there's probably a very hackish way, but it's not worth the pain.
What Brun
Gabriel Rossetti wrote:
Bruno Desthuilliers wrote:
Gabriel Rossetti a écrit :
I thought that since functions are objects, that I could obtain it's
nested functions.
Well, there's probably a very hackish way, but it's not worth the
pain.
What Bruno meant here, I believe
Bruno Desthuilliers wrote:
Gabriel Rossetti a écrit :
Hello,
I can't get getattr() to return nested functions,
Of course. Nested functions are not attributes of their container
function.
Ok
I tried this :
>>> def toto():
... def titi():
... pass
...
Gabriel Genellina wrote:
En Wed, 20 Aug 2008 05:34:38 -0300, Gabriel Rossetti
<[EMAIL PROTECTED]> escribi�:
I can't get getattr() to return nested functions, I tried this :
>>> def toto():
... def titi():
... pass
... f = getattr(toto, "t
Gabriel Rossetti a écrit :
Hello,
I can't get getattr() to return nested functions,
Of course. Nested functions are not attributes of their container function.
I tried this :
>>> def toto():
... def titi():
... pass
... f = getattr(toto, "titi&qu
En Wed, 20 Aug 2008 05:34:38 -0300, Gabriel Rossetti
<[EMAIL PROTECTED]> escribi�:
I can't get getattr() to return nested functions, I tried this :
>>> def toto():
... def titi():
... pass
... f = getattr(toto, "titi")
... print str(f)
.
Gabriel Rossetti <[EMAIL PROTECTED]> writes:
> I can't get getattr() to return nested functions, I tried this :
>
>>>> def toto():
> ... def titi():
> ... pass
> ... f = getattr(toto, "titi")
> ... print str(f)
> ...
&g
Hello,
I can't get getattr() to return nested functions, I tried this :
>>> def toto():
... def titi():
... pass
... f = getattr(toto, "titi")
... print str(f)
...
>>> toto()
Traceback (most recent call last):
File "&q
> "Duncan" == Duncan Booth <[EMAIL PROTECTED]> writes:
Duncan> Terry Jones <[EMAIL PROTECTED]> wrote:
>> Duncan Booth wrote:
Duncan> You'll kick yourself for not seeing it.
Duncan> If you changed fn_inner to:
Duncan> def fn_inner():
Duncan> a, v = v, a
Duncan> then you also changed 'a' and '
Terry Jones <[EMAIL PROTECTED]> wrote:
> Duncan Booth wrote:
>
>> You can use Python's bytecode disassembler to see what actually gets
>> executed here:
>>
>> >>> def fn_outer(v):
>> a=v*2
>> def fn_inner():
>> print "V:%d,%d" % (v,a)
>>
>> fn_inner()
>>
>> >>> import
[Referring to the thread at
http://mail.python.org/pipermail/python-list/2007-October/463348.html
with apologies for top posting (I don't have the original mail)]
Duncan Booth wrote:
> You can use Python's bytecode disassembler to see what actually gets
> executed here:
>
> >>> def fn_outer(v
On Oct 24, 2:52 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> beginner <[EMAIL PROTECTED]> wrote:
> > It is really convenient to use nested functions and lambda
> > expressions. What I'd like to know is if Python compiles fn_inner()
> > only once and chang
beginner <[EMAIL PROTECTED]> wrote:
> It is really convenient to use nested functions and lambda
> expressions. What I'd like to know is if Python compiles fn_inner()
> only once and change the binding of v every time fn_outer() is called
> or if Python compile and generat
"Gary Herron" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| beginner wrote:
| > Hi All,
| >
| > It is really convenient to use nested functions and lambda
| > expressions. What I'd like to know is if Python compiles fn_inner()
| > only once an
On Oct 23, 11:06 am, Gary Herron <[EMAIL PROTECTED]> wrote:
> beginner wrote:
> > Hi All,
>
> > It is really convenient to use nested functions and lambda
> > expressions. What I'd like to know is if Python compiles fn_inner()
> > only once and change
beginner wrote:
> Hi All,
>
> It is really convenient to use nested functions and lambda
> expressions. What I'd like to know is if Python compiles fn_inner()
> only once and change the binding of v every time fn_outer() is called
> or if Python compile and generate a ne
Hi All,
It is really convenient to use nested functions and lambda
expressions. What I'd like to know is if Python compiles fn_inner()
only once and change the binding of v every time fn_outer() is called
or if Python compile and generate a new function object every time. If
it is the l
On 2007-06-21, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> def f():
> a = 12
> def g():
> global a
> if a < 14:
> a=13
> g()
> return a
>
> print f()
>
> This function raises an error. Is there any way to access the a
> in f() from inside g().
>
> I co
[EMAIL PROTECTED] wrote:
> def f():
> a = 12
> def g():
> global a
> if a < 14:
> a=13
> g()
> return a
>
> print f()
>
> This function raises an error. Is there any way to access the a in f()
> from inside g().
>
> I could find few past discussions on
[EMAIL PROTECTED] wrote:
> def f():
> a = 12
> def g():
> global a
> if a < 14:
> a=13
> g()
> return a
>
> print f()
>
> This function raises an error. Is there any way to access the a in
> f() from inside g().
Yes. Pass it to g when calling the latt
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> def f():
> a = 12
> def g():
> global a
> if a < 14:
> a=13
> g()
> return a
>
> print f()
>
> This function raises an error. Is there any way to access the a in f()
> from inside g().
>
> I could find
def f():
a = 12
def g():
global a
if a < 14:
a=13
g()
return a
print f()
This function raises an error. Is there any way to access the a in f()
from inside g().
I could find few past discussions on this subject, I could not find
the simple answer wheth
Steve Holden wrote in
news:[EMAIL PROTECTED] in
comp.lang.python:
> Since we have a class that goes out of scope
>> when the function returns, and we don't need more than one instance,
>> why bother to make an instance? Why not use the class object itself?
>>
>> def whatever( new_ms ):
>>
>>
Frederic Rentsch wrote in news:mailman.1613.1162403556.11739.python-
[EMAIL PROTECTED] in comp.lang.python:
> Since we have a class that goes out of scope
> when the function returns, and we don't need more than one instance, why
> bother to make an instance? Why not use the class object itself?
Frederic Rentsch wrote:
> Rob Williscroft wrote:
>
>>Frederic Rentsch wrote in news:mailman.1556.1162316571.11739.python-
>>[EMAIL PROTECTED] in comp.lang.python:
>>
>>
>>
>>>Rob Williscroft wrote:
>>>
>>>
Frederic Rentsch wrote in news:mailman.1536.1162292996.11739.python-
>>
Rob Williscroft wrote:
> Frederic Rentsch wrote in news:mailman.1556.1162316571.11739.python-
> [EMAIL PROTECTED] in comp.lang.python:
>
>
>> Rob Williscroft wrote:
>>
>>> Frederic Rentsch wrote in news:mailman.1536.1162292996.11739.python-
>>>
Rob Williscroft wrote:
Carl Banks wrote:
> Not so fast. You can get at the nested function by peeking inside code
> objects (all bets off for Pythons other than CPython).
>
> import new
> def extract_nested_function(func,name):
> codetype = type(func.func_code)
> for obj in func.func_code.co_consts:
> i
bar'
> >
> > but it doesn't work as I expected.
>
> Functions don't get attributes automatically added to them the way
> class do. The main exception is the '__doc__' attribute, referring to
> the doc string value.
>
> > where do nested functi
Frederic Rentsch wrote in news:mailman.1556.1162316571.11739.python-
[EMAIL PROTECTED] in comp.lang.python:
> Rob Williscroft wrote:
>> Frederic Rentsch wrote in news:mailman.1536.1162292996.11739.python-
>>> Rob Williscroft wrote:
Frederic Rentsch wrote in news:mailman.1428.1162113628.11739.
Rob Williscroft wrote:
> Frederic Rentsch wrote in news:mailman.1536.1162292996.11739.python-
> [EMAIL PROTECTED] in comp.lang.python:
>
>
>> Rob Williscroft wrote:
>>
>>> Frederic Rentsch wrote in news:mailman.1428.1162113628.11739.python-
>>> [EMAIL PROTECTED] in comp.lang.python:
>>>
>>>
Frederic Rentsch wrote in news:mailman.1536.1162292996.11739.python-
[EMAIL PROTECTED] in comp.lang.python:
> Rob Williscroft wrote:
>> Frederic Rentsch wrote in news:mailman.1428.1162113628.11739.python-
>> [EMAIL PROTECTED] in comp.lang.python:
>>
>>
>> def whatever( new_ms ):
>> class nam
Rob Williscroft wrote:
> Frederic Rentsch wrote in news:mailman.1428.1162113628.11739.python-
> [EMAIL PROTECTED] in comp.lang.python:
>
>
>>def increment_time (interval_ms):
>> outer weeks, days, hours, minutes, seconds, mseconds # 'outer'
>> akin to 'global'
>> (...)
>>
Frederic Rentsch wrote in news:mailman.1428.1162113628.11739.python-
[EMAIL PROTECTED] in comp.lang.python:
>def increment_time (interval_ms):
> outer weeks, days, hours, minutes, seconds, mseconds # 'outer'
> akin to 'global'
> (...)
> mseconds = new_ms - s * 1000
Fredrik Lundh wrote:
> Frederic Rentsch wrote:
>
>
>> At some later point I need to increment my units some more and probably
>> will again a number of times. Clearly this has to go into a function.
>>
>
> since Python is an object-based language, clearly you could make your
> counter int
Frederic Rentsch wrote:
> At some later point I need to increment my units some more and probably
> will again a number of times. Clearly this has to go into a function.
since Python is an object-based language, clearly you could make your
counter into a self-contained object instead of writing
Diez B. Roggisch wrote:
>> If I may turn the issue around, I could see a need for an inner function
>> to be able to access the variables of the outer function, the same way a
>> function can access globals. Why? Because inner functions serve to
>> de-multiply code segments one would otherwise n
> If I may turn the issue around, I could see a need for an inner function
> to be able to access the variables of the outer function, the same way a
> function can access globals. Why? Because inner functions serve to
> de-multiply code segments one would otherwise need to repeat or to
> provi
ow Python loves namespaces, I thought I could do
>> this:
>>
>>
>>>>> foo.bar()
>>>>>
>> Traceback (most recent call last):
>> File "", line 1, in ?
>> AttributeError: 'function' object has no attribute 'b
t, and
>> you'll be able to access attributes and call it like a function.
>
> I turned Steven's question and portions of the answers into a Python FAQ
> entry:
>
> http://effbot.org/pyfaq/where-do-nested-functions-live.htm
>
> Hope none of the contributors mi
In <[EMAIL PROTECTED]>, Steven
D'Aprano wrote:
> Does this mean I'm wasting my time writing doc strings for nested
> functions? If there is no way of accessing them externally, should I make
> them mere # comments?
Whats the difference in "wasted time" betwe
On Sat, 28 Oct 2006 09:59:29 +0200, Fredrik Lundh wrote:
>> where do nested functions live?
>
> in the local variable of an executing function, just like the variable
> "bar" in the following function:
>
> def foo():
> bar = "who am I
tributes and call it like a function.
I turned Steven's question and portions of the answers into a Python FAQ
entry:
http://effbot.org/pyfaq/where-do-nested-functions-live.htm
Hope none of the contributors mind.
--
http://mail.python.org/mailman/listinfo/python-list
>>>foo.bar()
>
> Traceback (most recent call last):
> File "", line 1, in ?
> AttributeError: 'function' object has no attribute 'bar'
>
> but it doesn't work as I expected.
>
>
> where do nested functions live? How can you access
utomatically added to them the way
class do. The main exception is the '__doc__' attribute, referring to
the doc string value.
> where do nested functions live?
They live inside the scope of the function. Inaccessible from outside,
which is as it should be. Functions interact with the o
foo.bar()
> Traceback (most recent call last):
> File "", line 1, in ?
> AttributeError: 'function' object has no attribute 'bar'
>
> but it doesn't work as I expected.
>
> where do nested functions live?
in the local variable of an execu
ttributeError: 'function' object has no attribute 'bar'
but it doesn't work as I expected.
where do nested functions live? How can you access them, for example, to
read their doc strings?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Just wrote:
> In article <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] wrote:
>
> > Can doctests be added to nested functions too? (This can be useful to
> > me, I use nested function when I don't have attributes that I have to
> > remember, but I want to s
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> Can doctests be added to nested functions too? (This can be useful to
> me, I use nested function when I don't have attributes that I have to
> remember, but I want to split the logic in some subparts anyway).
Recently I have posted this same question on it.comp.lang.python, maybe
there aren't solutions, but I'd like to know what you think.
Can doctests be added to nested functions too? (This can be useful to
me, I use nested function when I don't have attributes that I have to
remember
Ben Cartwright wrote:
> The typical kludge is to wrap the variable in the outer function inside
> a mutable object, then pass it into the inner using a default argument:
>
> def outer():
> a = "outer"
> def inner(wrapa=[a]):
> print wrapa[0]
> wrapa[0] = "inner"
> retu
[EMAIL PROTECTED] wrote:
> Is it possible to change the value of a variable in the outer function
> if you are in a nested inner function?
Depends on what you mean by "changing the value". If you mean mutating a
mutable object, yes, it's possible. If you mean rebinding the name to a
different obje
[EMAIL PROTECTED] wrote:
> Is it possible to change the value of a variable in the outer function
> if you are in a nested inner function?
The typical kludge is to wrap the variable in the outer function inside
a mutable object, then pass it into the inner using a default argument:
def outer():
Is it possible to change the value of a variable in the outer function
if you are in a nested inner function?
For example:
def outer():
a = "outer"
def inner():
print a
a = "inner"
# I'm trying to change the outer 'a' here,
# but this st
Fredrik Lundh wrote:
> George Sakkis wrote:
>
>> It shouldn't come as a surprise if it turns out to be slower, since the
>> nested function is redefined every time the outer is called.
>
> except that it isn't, really: all that happens is that a new function object
> is created from
> prebuilt p
Thanks everybody for your help!
--
http://mail.python.org/mailman/listinfo/python-list
Duncan Booth wrote:
> Fredrik Lundh wrote:
>
> > George Sakkis wrote:
> >
> >> It shouldn't come as a surprise if it turns out to be slower, since
> >> the nested function is redefined every time the outer is called.
> >
> > except that it isn't, really: all that happens is that a new function
> >
Fredrik Lundh wrote:
> George Sakkis wrote:
>
>> It shouldn't come as a surprise if it turns out to be slower, since
>> the nested function is redefined every time the outer is called.
>
> except that it isn't, really: all that happens is that a new function
> object is created from prebuilt par
George Sakkis wrote:
> It shouldn't come as a surprise if it turns out to be slower, since the
> nested function is redefined every time the outer is called.
except that it isn't, really: all that happens is that a new function object is
created from
prebuilt parts, and assigned to a local varia
, such as how often you access the closure/parameter, and whether or
not there are other arguments to the function.
I frequently nest functions, but I do it in cases where I want to simplify
a function body and don't see any case for creating yet another generally
accessible method or
t; > ...
>> >
>> > is it a good practice or not?
>>
>> You have my blessing. Used well, it makes for more readable code.
>
> I'm not sure it's in general more readable; I typically use nested
> functions for closures only, not helper functions
1 - 100 of 127 matches
Mail list logo