Solved

QApp Python Script checking if GDT Table Variable is empty not working pythonic way?

  • 4 October 2022
  • 1 reply
  • 74 views

Userlevel 1

Greetings,

 

I just ran into an interesting problem:

 

In Qapp, when I script a GDT Variable to check if a another GDT Table or Table Variable is empty, it does not work using pythonic way. How can I get to check if a Table Attribute (list) is empty or not without coming up with other creative solutions? Basically, the Attribute (list) or Table appears to never be empty despite containing no data.

 

BID Table has _device, id and mac_limit attributes.

GDT Table has attribute “note” that I use for scripting.

When I check if BID Table (list) or BID.bid attribute (list) is empty is doesn’t return true for empty using pythonic way:

#Check if BID.bid (list) is empty:
if not $BID.bid:

  $cell = “PASSED: Bridge-Domains are not configured”.

 

Although empty, it doesn’t match and continues to go through next else statement: The value returned is “None”.

 

In the note, I run the following script:

try:

    if $mpls_ldp is None:

        $cell = "NOT APPLICABLE: Device is not a PE Device."

    else:

        if not $BID.bid:

            $cell = "PASSED: Bridge-Domains are not configured."

        else:

            code = 0

            result = []

            rc = $BID.GetRowCount()

            for x in range(rc):

                if $BID.mac_limit[x] is None:

                    code = code + 1

                    result.append("FAILED: " + str($BID.bid[x]) + " does not have a MAC address limit configured.")

           

            if code == 0:

                $cell = "PASSED: All Bridge-Domains have a MAC address limit configured."

            else:

                $cell = '\n'.join(result)

 

except:

    $cell = "NOT REVIEWED: Unable to validate configuration."

 

Qapp with BID Table having content:

 

BID Table without content:

 

GDT Table, note variable showing “NONE” from $BID.bid attribute (list) output, despite being empty:

 

Code:

 

icon

Best answer by dawal1337 4 October 2022, 16:23

View original

1 reply

Userlevel 1

I think I have found a workaround to my problem. It seems to work using the following method:

 

test = [None]

if $BID.bid == test:

<code below>

 

» returns True, if list is empty.

» returns False, if not empty.

 

Reply


Community |  Ideas

Facebook |  Instagram |  Youtube |  Twitter |  LinkedIn
Privacy & Security Statement  |  Terms & Conditions |  Impressum  |  UK Modern Slavery Statement