UnboundLocalError on local variable when reassigned after first use

The following code works as expected in both Python 2.5 and 3.0: a, b, c = (1, 2, 3) print(a, b, c) def test(): print(a) print(b) print(c) # (A) #c+=1 # (B) test() However, when I...

How can I implicitly convert another struct to my Type?

As it is MyClass x = 120;, is it possible to create such a custom class? If so, how can I do that?

Reference — What does this symbol mean in PHP?

What is this? This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this...

Python 3: UnboundLocalError: local variable referenced before assignment

The following code gives the error UnboundLocalError: local variable 'Var1' referenced before assignment: Var1 = 1 Var2 = 0 def function(): if Var2 == 0 and Var1 > 0: print("Result...

Easily aligning characters after whitespace in vim

I would like to create a mapped vim command that helps me align assignments for variables across multiple lines. Imagine I have the following text in a file: foo = 1; barbar ...

Python assigning multiple variables to same value? list behavior

I tried to use multiple assignment as show below to initialize variables, but I got confused by the behavior, I expect to reassign the values list separately, I mean b[0] and c[0] equal 0 as...

Lotus Notes Agent - extract attachments from DB to separate folders for each document

Have an assignment to do - it's to extract data from Lotus Notes DB including documents and their attachments. The purpose of this is to put it and store on the Sharepoint as a library. So far I...

C++ error: assignment of read-only variable

I have some C++ code that returns this error: error: assignment of read-only variable ‘parking’ The code: char const * const parking= "false"; if (phidgets.value(PHIDGET3V_1) > 1000) { ...

Check if a variable is between two numbers with Java

I have a problem with this code: if (90 >>= angle =<< 180) The error explanation is: The left-hand side of an assignment must be a variable. I understand what this means but how do I turn the...

Returning the inverse matrix from a cached object in R checking that input matrix has not changed

Disclosure: This is from a programming assignment from a Coursera Course called R programming. I originally had up the full code but took parts of it out since I realize I am not permitted to...

Python Multiple Assignment Statements In One Line

(Don't worry, this isn't another question about unpacking tuples.) In python, a statement like foo = bar = baz = 5 assigns the variables foo, bar, and baz to 5. It assigns these variables from...

Calculate days between two dates without using any date class

I am trying to right a program for my introduction to java course. The user enters their birthdate in the following format(19900506), the amount of days the person is then displayed. The program...

Can I destructure a tuple without binding the result to a new variable in a let/match/for statement?

I'd like to destructure a tuple and assign part of the result to a new variable and assign another part of the result to an existing. The following code illustrates the intent (it's a dumb example...

How to let android studio align assignment when reformating the code?

Let's assume we have this code: int x; double yyyy; float zzzzzzzz; x = 1; yyyy = 24.5d; zzzzzzzz = 1.3f; after I enabled: Settings -> Code Style-> Java -> Wrapping and Braces -> Align Variable...

Java: How to move a knight on a chessboard until no possible moves are left

I have an assignment to have a knight move around the chessboard until it either completes a full tour or has no where else to go. im having a problem figuring out how to have it actually stop...

Is assignment an operator in Python?

I checked the operator precedence in Python 3, and found that there is no assignment (=). I want to know if assignment is an operator or not. If not, why are there so many "assignment operator"...

Currency exchange rate java assignment

Hello I am looking for help on my homework assignment! So the prompt is as follows: " Write a program that prompts the user to enter the exchange rate from currency in US dollars to Chinese RMB....

Does C# 7 have array/enumerable destructuring?

In JavaScript ES6, you are able to destructure arrays like this: const [a,b,...rest] = someArray; where a is the first element in the array, b is the second, and rest is an array with the...

I am trying to change the value of an exposed variable in RPyC. I receive an error. What am I doing wrong?

I am using RPyC for a client-server application. I try to change the value of exposed_variable when I call exposed_change() method. I receive "UnboundLocalError: local variable 'exposed_variable'...

Python Global Variables - Not Defined?

I'm running into an issue where a global variable isn't "remembered" after it's modified in 2 different functions. The variable df is supposed to be a data frame, and it doesn't point to anything...

Speed up computation for Distance Transform on Image in Python

I would like to find the find the distance transform of a binary image in the fastest way possible without using the scipy package distance_trnsform_edt(). The image is 256 by 256. The reason I...

Typescript - Incorrectly inferring 'never'

This is a basic use-case: Initializing a variable with null then changing the value in some nested loop/function: let a: number | null = null; [1].forEach(() => { a = 1; }); if (a != null) ...

Sonarqube supports rules to enforce coding standards or not

Sonarqube produces issues with the code like bugs and security-related issues as vulnerabilities and code smell that could cause issues. Is there a way to add the coding standards to enforce...

Static program analysis: cppcheck flags redundant assignment on declaration of variable

imagine the following: #define OK 0 #define ERROR -1 int foo(void) { int rv = OK; rv = bar(); return rv; } in this instance, cppcheck would flag the line int rv = OK; as a...

What is best practice to websocket reconnect in react?

I have react app with ticket polling (ticket is part of link for websocket connection). Then I pass websocket object to another component, because only this (another) component should make...

<expression> expected, got '=' for variable assignment in Groovy

I've created following Groovy class in IntelliJ IDEA 1. package org.seleniumrun 2. 3. class Testing { 4. static void getJsonAsString(String endPointUrl) { 5. BufferedReader in =...

ValueError: No gradients provided for any variable in TensorFlow when building a GAN

I'm trying to build a GAN for a university assignment. My code is very similar to the intro example in this tutorial from TF's website. Below are what I think the relevant parts of the code (can...

Understanding result of fetching CKRecords with new async/await API

I am a bit confused on how to deal with complex Swift data types, their assignment to variables and accessing the values within. Hopefully someone can clarify the following: when trying to get...

Set up a bidirectional relationship between dog and owner (Java)

I am very new to programming and I'm working on an assignment for a dog auction program, where i want to write a method to give a dog to a person. I have an owner class, where I want to store dog...

How to implement copy propogation?

In compiler theory, copy propagation is the process of replacing the occurrences of targets of direct assignments with their values. A direct assignment is an instruction of the form x = y, which...