Python TypeError: 'NoneType' object is not subscriptable only showing on second iteration? : I am getting a really weird error. The function Choose_units() is called in a loop. It works the first time it is called but gives this error the second time. The error is on the line "units_used = UNITS.get(current_units)[0] "
I used some checks before the line and it shows that current_units != None. We were asked to use current_units as a global variable in the assignment. 




I used some checks before the line and it shows that current_units != None. But it still displays the same error and for some reason not on the first iteration. 

while True:
    print_menu();

    try:
      choice = int(input("What is your choice?: "));

    except:
      print("Please enter an integer only");
      continue;

    if choice == 1:
      Process_a_new_data_file(current_set);

    elif choice == 2:
      Choose_units();


def Choose_units():
    global current_units
    if current_units is not None:
            print("a")
    print(current_units)
    units_used = UNITS.get(current_units)[0]
    print("Current units in " + units_used)
    print("Choose new units:\n")
    for i in UNITS:
        print(str(i) + " - " + UNITS[i][0])
    while True:
        current_units = input("Which unit?\n")
        for i in UNITS:
            if(int(current_units) == i):
                return
        print("Please choose a unit from the list")
        continue

It should work without showing the error.  

My sample run:

 Main Menu
---------
1 - Process a new data file
2 - Choose units
3 - Edit room filter
4 - Show summary statistics
5 -Show temperature by date and time
6 -Show histogram of temperatures
7 - Quit
What is your choice?: 2
a
0
Current units in Celsius
Choose new units:

0 - Celsius
1 - Fahrenheit
2 - Kelvin
5 - Rankine
Which unit?
1
Main Menu
---------
1 - Process a new data file
2 - Choose units
3 - Edit room filter
4 - Show summary statistics
5 -Show temperature by date and time
6 -Show histogram of temperatures
7 - Quit
What is your choice?: 2
a
1
Traceback (most recent call last):
  File "Assignment9.py", line 274, in <module>
    main()
  File "Assignment9.py", line 253, in main
    Choose_units();
  File "Assignment9.py", line 79, in Choose_units
    units_used = UNITS.get(current_units)[0]
TypeError: 'NoneType' object is not subscriptable