All Questions
Tagged with local-variables variables
101 questions
0
votes
1
answer
115
views
Moving a local scoped variable to global scope so I can import it to another JS file
Im trying to convert an excel sheet into a json object in javascript and Im having problems retrieving the final data as it is scoped locally. I would like to take the variable labelled as "...
0
votes
1
answer
25
views
How does reinitailization works with local and top-level variable in dart?
bool isAdult = false;
isAdult=!isAdult;//error
void main(List<String> args) {
//If-statements
isAdult=!isAdult; //no error
int age = 21;
if (age >= 21) {
print('Adult 21');
} ...
1
vote
0
answers
5k
views
How to use a Terraform local variable in a file inside another folder(module)
I have a directory structure of my project as follows;
|
|- module1
| |- module1_main.tf
|
|- module2
| |- module2_main.tf
|
|- main.tf
|- locals.tf
in main.tf I am using both modules (module1 &...
0
votes
1
answer
1k
views
In Terraform is it possible to have a local in a variable?
I have this code:
locals {
pet_name = dog
}
variable "colors" {
default = "${local.pet_name}"
I'm getting a "Variables may not be used here" error message when I ...
4
votes
1
answer
173
views
Strange behavior of `unset` for local variables
I can't explain the following behavior of unset:
#!/bin/bash
my_unset() { unset "$@"; }
fn1() { local var; unset var; var=1; }
fn2() { local var; my_unset var; var=2; }
var=0
fn1; ...
0
votes
0
answers
21
views
Python function variable scoping and expressions [duplicate]
I notice that global variables in Python (3.9.10) can be accessed within functions, but not mutated as shown below:
No error:
def absolute_value(number):
print(y)
if number < 0:
...
0
votes
1
answer
386
views
Pug not rendering variables defined in res.render
Does anybody know why my tour variable is not rendered on the site. My paragraph is rendered but tour is undefined
app.get('/', (req, res) => {
res.status(200).render('base', {
tour: 'The ...
0
votes
1
answer
946
views
Python - Get name list of objects of a specified class in the namespace
I want to get a list of all dictionary objects that exist in the namespace.
I know that %whos() magic function will print the list, but as far as I could tell, it just prints and doesn't return ...
-1
votes
2
answers
285
views
How to stop variables becoming local?
I'm trying to create a function to verify if a move in a game is legal. At the top of my code, I declared the variable Valid.
p1 = [1,1]
p2 = [1,1]
turn = 1
move = 0
Valid = False
and later on, I ...
0
votes
2
answers
504
views
Python local variable 'message' referenced before assignment problem
liquid = [l_press,l_dosage,l_bottle,l_position,l_clog,l_counter]
for j in range(len(liquid)):
data = liquid_filling(liquid[j])
publish.single(liquid[j],data,qos = 0, hostname = ...
1
vote
1
answer
10k
views
React sending local variable to another file
I am new to React Framework. I am having trouble exporting a usestate value queryCity to another js file.
I have a code React index.js code like below:
import React, { useState } from "react&...
0
votes
0
answers
13
views
printing localVariable keeps giving error [duplicate]
console.log(localVariable keeps giving a reference error
var globalVariable = "A"; // a global variable
function testScope1() {
var localVariable = "B"; // a local ...
-1
votes
1
answer
74
views
Assigning variables in a function
In the code below, I can see that the variables end_line and internal_line are assigned to their characters but then below that in the for loop, another variable called end_line is being assigned to ...
-2
votes
1
answer
43
views
Function isn't working with a gobal variable. Should it be expected?
As title says, I can't have the variable "countDash" being used on my function if it's globaly, only local. Should it be like this?
What am I missing something? Thanks in advance.
//count
...
2
votes
0
answers
38
views
Python: A global variable in a local function possible? [duplicate]
Consider the programm:
x = 0
def f():
c = 2
def g():
c = 4
print(c)
print(c)
I want that the c in g() is the same as the c in f().
Normally one would use the keyword ...