xxxxxxxxxx
# Had the same issue today. Fixed it by
# editing the /usr/lib/python3/dist-packages/UbuntuDrivers/detect.py" file
# and replace line 835 with this line:
version = int(package_name.split('-')[-2])
# The only change I'm bringing is -2 instead of -1.
# Otherwise it raises a ValueError inside the try block and just
# doesn't give any value to the version variable.
# Check out https://bugs.launchpad.net/ubuntu/+source/ubuntu-drivers-common/+bug/1993019 if that was confusing
xxxxxxxxxx
"""
This happens when python thinks that your variable is local
(the scope is only within a specific function) and/or that
you have not assigned a value to the variable before in this
specific function (scope).
try:
- assigning the variable a value within the function
- Passing the variable to the function using it when calling the function
- Declaring the variable as global (bad practice)
Read more about this error in the source
"""
xxxxxxxxxx
#use the global keyword inside of the function
myVariable = 0
def some_function():
global myVariable
print(myVariable)
myVariable = 10
some_function()
xxxxxxxxxx
r = 0
list = ['apple','lime','orange']
def list_list(x):
for i in x:
r +=1
print r
list_list(list)
xxxxxxxxxx
Hey Mate,
Issue is that you're calling variable r inside the def list_list.
(reccomend to always keep your def on top or in another .py file to avoid this confusion)
happy coding.
Try:
def list_list(x, y):
for i in x:
y +=1
print (y)
r = 0
list = ['apple','lime','orange']
list_list(list, r)
xxxxxxxxxx
"""
You can trick the error :D
Use a list instead of a variable
example
"""
current = [0] # then refer to it as current[0]