Skip to main content
Filter by
Sorted by
Tagged with
524 votes
11 answers
207k views

What does nonlocal do in Python 3.x? To close debugging questions where OP needs nonlocal and doesn't realize it, please use Is it possible to modify variable in python that is in outer, but not ...
ooboo's user avatar
  • 17.3k
185 votes
12 answers
277k views

Let's say that a function A is required only by function B, should A be defined inside B? Simple example. Two methods, one called from another: def method_a(arg): some_data = method_b(arg) def ...
nukl's user avatar
  • 10.6k
118 votes
4 answers
16k views

Okay, bear with me on this, I know it's going to look horribly convoluted, but please help me understand what's happening. from functools import partial class Cage(object): def __init__(self, ...
noio's user avatar
  • 5,822
94 votes
7 answers
99k views

What benefit or implications could we get with Python code like this: class some_class(parent_class): def doOp(self, x, y): def add(x, y): return x + y return add(x, y) ...
Hosam Aly's user avatar
  • 42.6k
63 votes
1 answer
4k views

I'm new to Rust and have been looking through the source code a bit, and found this: #[stable(feature = "fs_read_write_bytes", since = "1.26.0")] pub fn write<P: AsRef<Path&...
Challe's user avatar
  • 731
53 votes
11 answers
93k views

I have the following piece of code: function initValidation() { // irrelevant code here function validate(_block){ // code here } } Is there any way I can call the validate() ...
Eduard Luca's user avatar
  • 6,622
34 votes
1 answer
7k views

I recently found out that gcc allows the definition of nested function. In my opinion, this is a cool feature, but I wonder how to implement it. While it is certainly not difficult to implement ...
fuz's user avatar
  • 94.7k
29 votes
2 answers
1k views

Let we have this code: def big_function(): def little_function(): ....... ......... The Python documentation says about def statement: A function definition is an executable ...
dondublon's user avatar
  • 701
28 votes
7 answers
170k views

I am trying to set up a function to reformat a string that will later be concatenated. An example string would look like this: Standard_H2_W1_Launch_123x456_S_40K_AB Though sometimes the "S" doesn't ...
samanthathyme's user avatar
23 votes
11 answers
13k views

I know that nested functions are not part of the standard C, but since they're present in gcc (and the fact that gcc is the only compiler i care about), i tend to use them quite often. Is this a bad ...
LB40's user avatar
  • 12.4k
16 votes
5 answers
37k views

Can anyone explain why 0's and 1's are printed and not anything else? Thank you! func makeFunction(name string) func() { fmt.Println("00000") return func() { makeFunction2("abcef") ...
kunrazor's user avatar
  • 371
15 votes
1 answer
2k views

For example, public int DoSomething(in SomeType something){ int local(){ return something.anInt; } return local(); } Why does the compiler issue an error that the something variable cannot ...
Frank's user avatar
  • 1,110
14 votes
2 answers
2k views

Some of coworkers are saying that nesting functions is bad for performance and I wanted to ask about this. Lets say I have the function: function calculateStuff() { function helper() { // ...
user1413969's user avatar
  • 1,301
11 votes
5 answers
9k views

I am trying to understand, how exactly variable binding in python works. Let's look at this: def foo(x): def bar(): print y return bar y = 5 bar = foo(2) bar() This prints 5 which ...
gruszczy's user avatar
  • 42.4k
11 votes
1 answer
3k views

I've had pretty good success using this answer to profile my Cython code, but it doesn't seem to work properly with nested functions. In this notebook you can see that the profile doesn't appear when ...
C_Z_'s user avatar
  • 7,876
9 votes
3 answers
4k views

I'm just learning some Swift and I've come across the section that talks about nesting functions: Functions can be nested. Nested functions have access to variables that were declared in the outer ...
Jona's user avatar
  • 1,061
9 votes
1 answer
663 views

In MATLAB you can have multiple functions in one .m file. There is of course the main function, and then either nested or local functions. Examples of each function type: % myfunc.m with local ...
Wolfie's user avatar
  • 30.7k
8 votes
4 answers
5k views

I prefer using nested functions instead of methods or global functions in Python whenever possible. So I decided to test their performance because it seams that when you define a function in another ...
nima's user avatar
  • 6,753
8 votes
3 answers
5k views

As far as I know, there are three ways to define functions in JavaScript. 1. Declaration function handleEvent(e) {} 2. Assignment var handleEvent = function(e) {} 3. Arrow var handleEvent = (e) =&...
Snackoverflow's user avatar
7 votes
5 answers
5k views

Is it possible to write portable C code using nested functions/blocks? I understand that gcc only supports nested functions as an non-standard extension, and clang only supports blocks - but is there ...
Isaac Turner's user avatar
  • 2,961
7 votes
4 answers
521 views

Could someone explain why the following program fails: def g(f): for _ in range(10): f() def main(): x = 10 def f(): print x x = x + 1 g(f) if __name__ == '__main__': main() ...
Kan Li's user avatar
  • 8,837
6 votes
2 answers
5k views

I used to write nested helper functions (which, btw, ocasionally used parameters of outer functions and are recursive) in Haskell like this (loop): sum a b = let loop s i = if i > b then s else ...
Artem Pelenitsyn's user avatar
6 votes
2 answers
8k views

here is my code: def f(x): def g(n): if n < 10: x = x + 1 g(n + 1) g(0) When I evaluate f(0), there would be an error "x referenced before assignment". ...
octref's user avatar
  • 6,841
6 votes
1 answer
426 views

Background information I am setting up a function which creates a date array based on a start date and an end date. The function will receive start and end dates, which have first been formatted ...
rabbitco's user avatar
  • 2,860
5 votes
3 answers
7k views

I have this code: function test() function awesome() print("im awesome!") end function notawesome() print("im not awesome.") end function notevenawesome() ...
crazicrafter1's user avatar

1
2 3 4 5
9