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.python-
.
where do nested functions live?
They live inside the scope of the function. Inaccessible from outside,
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
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:
if
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
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.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?
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 ):
class scope
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'
(...)
mseconds =
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 namespace(
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.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#
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 need to
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
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 into a
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
, 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 executing function, just like the variable
bar in the following function:
def foo():
bar = who am I? where do I live?
(yes, an inner
, in ?
AttributeError: 'function' object has no attribute '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 functions live
, 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 them, for example, to
read their doc strings?
It doesn't live anywhere: if I wrote the function
def foo():
locvar = 23
return locvar
would
Ben Finney wrote:
If you want something that can be called *and* define its attributes,
you want something more complex than the default function type. Define
a class that has a '__call__' attribute, make an instance of that, and
you'll be able to access attributes and call it like a
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? where do I live?
(yes, an inner function is *created
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 between using or # as delimiters
for the
Fredrik Lundh wrote:
Ben Finney wrote:
If you want something that can be called *and* define its attributes,
you want something more complex than the default function type. Define
a class that has a '__call__' attribute, make an instance of that, and
you'll be able to access attributes and
):
File stdin, 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 executing function, just like the variable
bar in the following function:
def foo
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
provide a
24 matches
Mail list logo