Variable Name Error "Is Undefined" Even Though "Variables.Less" Imported

Variable Name Error is undefined even though variables.less imported

This other question ultimately led me to the right answer.

It looks like the LESS compiler is silently failing if files are encoded with a BOM. (That's a Byte Order Mark for those not familiar with the term.) This is the default setting in some editors, such as Visual Studio.

The compiler barfs up an error on the BOM if it's in your root file, but seems to fail silently for @import-ed files.

Try saving your files as UTF-8 without a BOM, and see if that solves your problem.

Less complaining about @brand-success is undefined, even though it is in variables.less

I placed @import 'app/bower_components/bootstrap/less/bootstrap'; in style.less which fixed it. But this is really a hack...something else is wrong and if anyone can figure out why, that would be great.

Python NameError, variable 'not defined'

You need to define the variable "lives" outside of the function main, then any function where you want to reference that global variable you say "global lives." When you are in a function and assign a value to a variable, it assumes it is in the local scope. using "global lives" tells that function to look to the global scope as the reference of lives.

import random
import time

lives = 10
win = False
guess = 0
rand_num = 45

def main():
global guess, rand_num, lives, win
win = False
rand_num = 45
lives = 10
while lives > 0 and win == False:
guess = int(input("Guess a number!"))
compare()
print("Well done!")
time.sleep(3)

def compare():
global guess, rand_num, lives, win
if guess == rand_num:
print("You guessed correct!")
win = True
elif guess > rand_num:
print ("Guess lower!")
lives = lives - 1
else:
print ("Guess higher!")
lives = lives - 1

def repeat():
replay = input("would you like to play again? Y/N")
if replay == "Y":
print("enjoy!")
main()
elif replay == "N":
"Goodbye then, hope you enjoyed!"
time.sleep(3)
os._exit
else:
print("please enter Y or N")
repeat()

main()
repeat()

variable @fontAwesomeEotPath_iefix is undefined

Notice that your bootstrap_and_overrides.css.less doesn't have the variable the error is complaining about.

Add the following line with the other @fontAwesome variables and you should be good.

@fontAwesomeEotPath_iefix: asset-path("fontawesome-webfont.eot#iefix");

Or update your twitter bootstrap install by running rails g bootstrap:install -f.

Defining variables across files in Less CSS

Fixed. The problem was the encoding after all: the LESS compiler was skipping all wrongly encoded files. Apparently Sublime Text doesn't properly save to UTF-8 without BOM even if you tell it to; my files were all in either ANSI or UTF-8 with BOM. I had to resort to Notepad++ in order to convert them to plain UTF-8. I feel stupid now.

Source: Variable Name Error "is undefined" even though "variables.less" imported

Python - Variable in function not defined

The error occurs when I reach destroy_window1(), where i get the following message: "NameError: name 'e1' is not defined". How can I solve this problem?

The problem is that the destroy_window1() function doesn't know about the e1 variable, because e1 is defined within the window1() function (and its not global).

A simple fix is to put all the e variables into a list and pass that list as an argument to the destroy_window1() function. Make the list with a simple for loop, this not only solves your problem, but it also makes your code cleaner, easier to read, and easier to change it's functionality in future.

Like so:

def destroy_window1(e_list):
global Guess
Guess = []

for e_item in e_list:
Guess.append(e_item.get())

master1.destroy()
window2()

def window1():

master1 = Tk()
master1.title('Lottery')
Label(master1, text="Guess numbers:").grid(row=0)

e_list = []

for i in range(7):
temp_e = e1 = Entry(master1, width=2)
temp_e.grid(row=0, column=i, padx=5)
e_list.append(temp_e)

master1.grid_columnconfigure(6, minsize=20) # Creates an empty column (nr. 6) with width 20

Button(master1, text='OK', command=lambda :destroy_window1(e_list)).grid(row=3, column=3, sticky=W, pady=5)

master1.mainloop()

Part of this solution involves a lambda function. This is because (as you may have noticed) the command option normally can't take arguments for the functions. The use of a lambda functions makes this possible. (Read up on Lambda Functions Here)



Related Topics



Leave a reply



Submit