Re: Making command-line args available to deeply-nested functions

2021-09-10 Thread Loris Bennett
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

Re: Making command-line args available to deeply-nested functions

2021-08-31 Thread George Fischhof
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

Re: Making command-line args available to deeply-nested functions

2021-08-29 Thread George Fischhof
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

Re: Making command-line args available to deeply-nested functions

2021-08-26 Thread Loris Bennett
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

Re: Making command-line args available to deeply-nested functions

2021-08-23 Thread George Fischhof
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

Re: Making command-line args available to deeply-nested functions

2021-08-23 Thread Loris Bennett
>> >> >> 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

Re: Making command-line args available to deeply-nested functions

2021-08-21 Thread George Fischhof
. > > > > 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

Making command-line args available to deeply-nested functions

2021-08-20 Thread Loris Bennett
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

Re: Making command-line args available to deeply-nested functions

2021-08-20 Thread Loris Bennett
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

Re: Variable scope in nested functions

2018-01-29 Thread Prahallad Achar
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

Re: Variable scope in nested functions

2018-01-29 Thread Chris Angelico
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

Variable scope in nested functions

2018-01-29 Thread Prahallad Achar
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

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
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

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Antoon Pardon
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

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
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

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Marko Rauhamaa
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

Re: Nested functions, how do they work (stack related)

2016-12-13 Thread Veek M
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

Nested functions, how do they work (stack related)

2016-12-12 Thread Veek M
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

Re: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data...

2011-08-24 Thread Steven D'Aprano
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

Re: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data...

2011-08-24 Thread Adam Jorgensen
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

Re: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data...

2011-08-24 Thread Peter Otten
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

Weird interaction with nested functions inside a decorator-producing function and closuring of outer data...

2011-08-24 Thread Adam Jorgensen
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

Re: Classes: nested functions vs. private methodes

2010-05-07 Thread Steven D'Aprano
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

Re: Classes: nested functions vs. private methodes

2010-05-06 Thread Tim Roberts
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

Re: Classes: nested functions vs. private methodes

2010-05-06 Thread Richard Lamboj
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): > >

Re: Classes: nested functions vs. private methodes

2010-05-06 Thread 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): > def blub(var1, var2): > do something... > blub(1, 5) The disadvantage of nested functions i

Classes: nested functions vs. private methodes

2010-05-06 Thread Richard Lamboj
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

Re: improve this newbie code/nested functions in Python?

2009-03-21 Thread Esmail
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

Re: improve this newbie code/nested functions in Python?

2009-03-21 Thread Paul Hankin
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

Re: improve this newbie code/nested functions in Python?

2009-03-20 Thread Esmail
> 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

Re: improve this newbie code/nested functions in Python?

2009-03-20 Thread Terry Reedy
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

Re: improve this newbie code/nested functions in Python?

2009-03-20 Thread Esmail
> 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

Re: improve this newbie code/nested functions in Python?

2009-03-20 Thread pruebauno
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

Re: improve this newbie code/nested functions in Python?

2009-03-20 Thread Esmail
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

Re: improve this newbie code/nested functions in Python?

2009-03-19 Thread Terry Reedy
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

improve this newbie code/nested functions in Python?

2009-03-19 Thread Esmail
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

Re: getattr() on nested functions?

2008-08-21 Thread castironpi
;            pass > >        return resultToXml(locals()[action](*args)) > > >    def __task2(self, action, *args): > >        def request(params): > >            pass > >        def submit(params, values): > >            pass > >        def update(pa

Re: getattr() on nested functions?

2008-08-21 Thread Bruno Desthuilliers
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

Re: getattr() on nested functions?

2008-08-21 Thread Gabriel Rossetti
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

Re: getattr() on nested functions?

2008-08-21 Thread Bruno Desthuilliers
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

Re: getattr() on nested functions?

2008-08-21 Thread Gabriel Rossetti
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

Re: getattr() on nested functions?

2008-08-20 Thread Terry Reedy
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

Re: getattr() on nested functions?

2008-08-20 Thread Gabriel Rossetti
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 ...

Re: getattr() on nested functions?

2008-08-20 Thread Gabriel Rossetti
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

Re: getattr() on nested functions?

2008-08-20 Thread Bruno Desthuilliers
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

Re: getattr() on nested functions?

2008-08-20 Thread Gabriel Genellina
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) .

Re: getattr() on nested functions?

2008-08-20 Thread Hrvoje Niksic
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

getattr() on nested functions?

2008-08-20 Thread Gabriel Rossetti
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

Re: Speed of Nested Functions & Lambda Expressions

2007-12-07 Thread Terry Jones
> "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 '

Re: Speed of Nested Functions & Lambda Expressions

2007-12-07 Thread Duncan Booth
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

Re: Speed of Nested Functions & Lambda Expressions

2007-12-06 Thread Terry Jones
[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

Re: Speed of Nested Functions & Lambda Expressions

2007-10-24 Thread beginner
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

Re: Speed of Nested Functions & Lambda Expressions

2007-10-24 Thread Duncan Booth
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

Re: Speed of Nested Functions & Lambda Expressions

2007-10-23 Thread Terry Reedy
"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

Re: Speed of Nested Functions & Lambda Expressions

2007-10-23 Thread beginner
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

Re: Speed of Nested Functions & Lambda Expressions

2007-10-23 Thread Gary Herron
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

Speed of Nested Functions & Lambda Expressions

2007-10-23 Thread beginner
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

Re: Globals in nested functions

2007-06-21 Thread Neil Cerutti
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

Re: Globals in nested functions

2007-06-21 Thread Stef Mientki
[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

Re: Globals in nested functions

2007-06-21 Thread Bjoern Schliessmann
[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

Re: Globals in nested functions

2007-06-21 Thread Duncan Booth
"[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

Globals in nested functions

2007-06-21 Thread [EMAIL PROTECTED]
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

Re: Where do nested functions live?

2006-11-01 Thread Rob Williscroft
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 ): >> >>

Re: Where do nested functions live?

2006-11-01 Thread Rob Williscroft
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?

Re: Where do nested functions live?

2006-11-01 Thread Steve Holden
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- >>

Re: Where do nested functions live?

2006-11-01 Thread Frederic Rentsch
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:

Re: Where do nested functions live?

2006-11-01 Thread Fredrik Lundh
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

Re: Where do nested functions live?

2006-11-01 Thread Carl Banks
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

Re: Where do nested functions live?

2006-11-01 Thread Rob Williscroft
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.

Re: Where do nested functions live?

2006-10-31 Thread Frederic Rentsch
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: >>> >>>

Re: Where do nested functions live?

2006-10-31 Thread Rob Williscroft
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

Re: Where do nested functions live?

2006-10-31 Thread Frederic Rentsch
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' >> (...) >>

Re: Where do nested functions live?

2006-10-30 Thread Rob Williscroft
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

Re: Where do nested functions live?

2006-10-29 Thread Frederic Rentsch
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

Re: Where do nested functions live?

2006-10-29 Thread Fredrik Lundh
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

Re: Where do nested functions live?

2006-10-29 Thread Frederic Rentsch
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

Re: Where do nested functions live?

2006-10-28 Thread Diez B. Roggisch
> 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

Re: Where do nested functions live?

2006-10-28 Thread Frederic Rentsch
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

Re: Where do nested functions live?

2006-10-28 Thread Andrea Griffini
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

Re: Where do nested functions live?

2006-10-28 Thread Marc 'BlackJack' Rintsch
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

Re: Where do nested functions live?

2006-10-28 Thread Steven D'Aprano
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

Re: Where do nested functions live?

2006-10-28 Thread Fredrik Lundh
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

Re: Where do nested functions live?

2006-10-28 Thread Steve Holden
>>>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

Re: Where do nested functions live?

2006-10-28 Thread Ben Finney
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

Re: Where do nested functions live?

2006-10-28 Thread Fredrik Lundh
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

Where do nested functions live?

2006-10-28 Thread Steven D'Aprano
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

Re: Doctests for nested functions

2006-09-23 Thread Paddy
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

Re: Doctests for nested functions

2006-09-23 Thread Just
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).

Doctests for nested functions

2006-09-22 Thread bearophileHUGS
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

Re: Variables in nested functions

2006-08-30 Thread Bryan Olson
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

Re: Variables in nested functions

2006-08-30 Thread Bruno Desthuilliers
[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

Re: Variables in nested functions

2006-08-29 Thread Ben Cartwright
[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():

Variables in nested functions

2006-08-29 Thread zero . maximum
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

Re: nested functions

2006-06-15 Thread Kent Johnson
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

Re: nested functions

2006-06-15 Thread Gregory Petrosyan
Thanks everybody for your help! -- http://mail.python.org/mailman/listinfo/python-list

Re: nested functions

2006-06-15 Thread George Sakkis
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 > >

Re: nested functions

2006-06-15 Thread Duncan Booth
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

Re: nested functions

2006-06-15 Thread Fredrik Lundh
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

Re: nested functions

2006-06-15 Thread Duncan Booth
, 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

Re: nested functions

2006-06-14 Thread Georg Brandl
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   2   >