local-variables Questions

0

The following prints {'a': 'a', 'b': 'b'}: def foo(a: str = "a", b: str = "b") -> None: print(locals()) foo() # Prints {'a': 'a', 'b': 'b'} Which I'd expect as locals in Py...
Dulciana asked 12/8, 2024 at 18:32

3

Solved

Sometimes I come up with long spreadsheet formulas, such as this one to create "data bars" using Unicode characters (addresses are relative to G3): = rept("█"; floor(10 * F3 / max(F$1:F$999))) &a...
Dorotheadorothee asked 21/7, 2016 at 15:14

2

Solved

Today, I stumbled over something in Perl I was not aware of: it "localizes" the variable that the elements of the list iterated over is assigned to. This, of course, is documented in the Perl docu...
Ahrendt asked 15/2, 2017 at 7:51

6

Solved

Why most of the time should I use const instead of let in JavaScript? As we know if we use const then we can't reassign value later. Then why not use let instead of const?
Consistent asked 11/12, 2016 at 13:22

12

For example, in MS-SQL, you can open up a query window and run the following: DECLARE @List AS VARCHAR(8) SELECT @List = 'foobar' SELECT * FROM dbo.PubLists WHERE Name = @List How is this done...
Cutshall asked 20/4, 2009 at 2:28

1

Solved

When I compile the following code, I get a warning (https://godbolt.org/z/Tx7v6jWf1): void foo() { int _; // warning: name-independent declarations only available with // '-std=c++2c' or '-std=g...
Meggy asked 7/1, 2024 at 12:38

6

Solved

In another question I posted someone told me that there is a difference between: @variable and: variable in MySQL. He also mentioned how MSSQL has batch scope and MySQL has session scope. Can som...

1

I'm trying to rollback the local variable v1 from 5 to 2 with ROLLBACK statement in my_proc() procedure but v1 is not rollbacked keeping 5 as shown below: DELIMITER $$ CREATE PROCEDURE my_pr...
Decani asked 16/12, 2023 at 23:18

5

Solved

I am trying to define and initialize a MySQL variable for a query. I have the following: DECLARE @countTotal INT; SET @countTotal = SELECT COUNT(*) FROM nGrams; I am using MySQL in Netbeans and it...
Pleurodynia asked 2/12, 2012 at 15:24

2

Solved

There is an almost identical, but not really answered question here. I am migrating an application from MS SQL Server to PostgreSQL. In many places in code I use local variables so I would like to...
Charitacharitable asked 1/7, 2010 at 12:30

4

Solved

As in this question, when a local variable not defined is used within its own assignment, it is evaluated to nil. x = x # => nil But when the name of a local variable conflicts with an exist...
Vitalis asked 3/10, 2012 at 10:33

5

Here is some question I wondered about. Given the following code, can we be certain about its output? void f() { int i = 0; z: if(i == 1) goto x; else goto u; int a; x: if(a == 10) goto y; ...
Andesite asked 22/7, 2011 at 14:4

11

Solved

Based on my reference, primitive types have default values and Objects are null. I tested a piece of code. public class Main { public static void main(String[] args) { int a; System.out.println(...

2

Solved

One of my faviourite mistakes in Javascript is to forget to define variables I am using locally in a function. As you all know, due to scope, this is not always an error. Is there any way in Visual...
Zilpah asked 27/3, 2021 at 14:10

14

Solved

When I try this code: a, b, c = (1, 2, 3) def test(): print(a) print(b) print(c) c += 1 test() I get an error from the print(c) line that says: UnboundLocalError: local variable 'c' reference...
Staffer asked 16/12, 2008 at 3:6

3

Solved

I have the following Ruby code: local_var = "Hello" def hello puts local_var end hello I get the following error: local_variables.rb:4:in 'hello': undefined local variable or method 'local_v...
Trudytrue asked 12/3, 2012 at 16:49

4

Solved

Hi I have a observable user$ with a lot of properties (name, title, address...) component{ user$:Observerable<User>; constructor(private userService:UserService){ this.user$ = this.userSe...

6

Solved

I am trying to access a local function variable outside the function in Python. I can make code like this work with global variables: bye = '' def hi(): global bye bye = 5 sigh = 10 hi() ...
Poacher asked 11/10, 2013 at 19:43

3

Solved

If there is a global variable and the function has a parameter with the same name, and desired result is the sum of the local and global variable, how can we refer the global function in this parti...
Chemotaxis asked 18/3, 2014 at 22:24

3

EDIT2: A minimal demonstration is: code = """\ a=1 def f1(): print(a) print(f1.__closure__) f1() """ def foo(): exec(code) foo() Which gives: None Traceback (most...
Bitthia asked 22/5, 2022 at 6:14

3

Can you have a static variable in a static method? Would the value of this variable be preserved across all calls to the method? eg. public static void MyMethod() { static int x = 0; x++; }
Cozy asked 24/12, 2010 at 10:12

2

Solved

Consider the following code: private unsafe void Function() { int length; // This line raises error CS1686, "Local 'length' or its members cannot have their address taken and be used inside...
Intercolumniation asked 7/12, 2021 at 23:43

5

I would like to conditionally declare a local variable in a function, based on a template bool parameter. So if it is true it should be there, otherwise shouldn't be there in the sense that I don't...
Surreptitious asked 7/12, 2021 at 9:21

1

Solved

Consider this snippet: #include <iostream> #include <string> #include <string_view> using namespace std::literals; class A { public: std::string to_string() const noexcept { ...
Concurrent asked 23/8, 2021 at 13:26

1

The following code snippet works as expected: def test(): print(f'local symbol table before exec : {locals()}') exec('a = 0') print(f'local symbol table after exec : {locals()}') test() # print...
Naamann asked 21/5, 2021 at 19:6

© 2022 - 2025 — McMap. All rights reserved.