• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Issue with checking if array item is None or is not None

<button aria-describedby="--stacks-s-tooltip-4l2nld1j" aria-label="Bookmark" aria-pressed="false" class="js-bookmark-btn s-btn s-btn__unset c-pointer py4 js-gps-track" data-controller="s-tooltip" data-gps-track="post.click({ item: 1, priv: 0, post_type: 1 })" data-s-tooltip-placement="right" data-selected-classes="fc-yellow-600"></button><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" height="18" viewbox="0 0 19 18" width="19"></svg>

 

I have a function that is checking a 2D array for None objects. Sort of like a board game with empty slots(except they contain None). I created the array with None at each spot. When I test if it contains None, it says nope.

I understand it is better to use is and is not rather than == and != . I've heard that None objects can be treated as False in weird cases.

Here is a code snippet:

def set_inhabitants(self,locXY,obj,force=False):
    x = locXY[0]
    y = locXY[1]

    print('The spot contains',self._data[x][y] )
    print('The item here is None? ', end='')
    print (self._data[x][y] is None)
    #Spot is empty
    if self._data[x][y] is None:
        self._data[x][y] = obj
    #Spot is full  
    elif self._data[x][y] is not None and force == False:
        print(locXY, 'Spot is not None. Doing Nothing') 
    elif self._data[x][y] is not None and force == True:
        self._data[x][y] = obj
    
b = Board(2,2)
b.print_array()

b.set_inhabitants( (1,1),'A', force=False) 

print('')
print( b.print_array())

Output:

## Board Data Begin ##

[None]  [None]  

[None]  [None]  

## Board Data End ##

The spot contains [None]
The item here is None? False
(1, 1) Spot is not None. Doing Nothing

## Board Data Begin ##

[None]  [None]  

[None]  [None]  

Board Data End