<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Scope of Class Obj in Python in Other Security</title>
    <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951518#M391</link>
    <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I need to work on my rankings &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 31 Oct 2023 14:38:34 GMT</pubDate>
    <dc:creator>Marcel Zehnder</dc:creator>
    <dc:date>2023-10-31T14:38:34Z</dc:date>
    <item>
      <title>Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951462#M385</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;
&lt;P&gt;This is the first time I've tried to use Developer Hub community Support. &amp;nbsp;Please let me know if I need to take a different approach.&lt;/P&gt;
&lt;P&gt;Here is my problem.&lt;/P&gt;
&lt;PRE&gt;# I create a class and inside the class I only have integer variables.  &lt;BR /&gt;# I then create an object from the class and go into a while loop, parsing json data and incrementing counters in obj. &lt;BR /&gt;# However, when I exit the while loop and execute the printme instance method, all the integer variables are always zero.&lt;BR /&gt;# Why isn't the object (instance of the class) keeping the values?&lt;BR /&gt;# The structure of the script is like this&lt;BR /&gt;class VerdictStats:&lt;BR /&gt;    def __init__(self):&lt;BR /&gt;        self.noVerdict = 0&lt;BR /&gt;        self.phishing = 0&lt;BR /&gt;        &amp;lt;etc for more variables&amp;gt;&lt;BR /&gt;&lt;BR /&gt;    def printme(self):&lt;BR /&gt;        print(f"   noVerdict:  {self.noVerdict}")&lt;BR /&gt;        print(f"    Phishing: {self.phishing}")&lt;BR /&gt;        &amp;lt;etc for other variables&amp;gt;&lt;BR /&gt;        return&lt;BR /&gt;&lt;BR /&gt;# I then create the object in Global Scope.&lt;BR /&gt;verdictObj = VerdictStats()&lt;BR /&gt;&lt;BR /&gt;# I then enter a while loop and query Cisco Email Threat Defense (ETD) via API and parse the json an increment the counters&lt;BR /&gt;while total_messages_retrieved &amp;lt; total_messages_to_scan:&lt;BR /&gt;&lt;BR /&gt;    response = requests.request(... send the query and receive the response...)&lt;BR /&gt;    response_dict = json.loads[response.text)&lt;BR /&gt;    # then get message list out of dict&lt;BR /&gt;    # then loop through all the messages&lt;BR /&gt;    # all this works fine - I can see all the data if I print it&lt;BR /&gt;    # Now increment the instance object if I see certain things in message json data&lt;BR /&gt;    try:&lt;BR /&gt;        verdict = message["verdict"]&lt;BR /&gt;        if verdict == "phishing":&lt;BR /&gt;          verdictObj.phishing += 0&lt;BR /&gt;        &amp;lt;etc for other verdicts&amp;gt;&lt;BR /&gt;# the loop continues through all messages&lt;BR /&gt;# script falls out of while loop and back into Global scope&lt;BR /&gt;# I then call the printme instance method and all the counters are zeros&lt;BR /&gt;verdictObj.printme()&lt;BR /&gt;# and the output is all zeros&lt;BR /&gt;# can anyone tell me why the instance object is not keeping the data?&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;          &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 13:55:36 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951462#M385</guid>
      <dc:creator>dalthami</dc:creator>
      <dc:date>2023-10-31T13:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951466#M386</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/91359"&gt;@dalthami&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;you are using the += operator to increment the counters and so this operator creates a new object with the updated value, but it does not assign the new object to the verdictObj variable in your code. Try this, it will&amp;nbsp; increment the phishing attribute on the verdictObj instance.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if verdict == "phishing":
  verdictObj.phishing += 1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; Hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 13:28:19 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951466#M386</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2023-10-31T13:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951478#M387</link>
      <description>&lt;P&gt;Hi bigevilbeard.&lt;BR /&gt;My mistake in my posting (too much pseudo-code in trying to describe the problem – sorry about that).&lt;BR /&gt;Here is the actual code. I’m doing exactly what you suggest.&lt;BR /&gt;&lt;BR /&gt;originalVerdict = verdict["originalVerdict"]&lt;BR /&gt;if bool(originalVerdict):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; match originalVerdict:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "phishing":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.phishing += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.threat_total += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "bec":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.bec += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.threat_total += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "scam":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.scam += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.threat_total += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;case "malicious":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;originalVerdictsObj.malicious += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;originalVerdictsObj.threat_total += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "spam":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.spam += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.unwanted_total += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "graymail":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.graymail += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.unwanted_total += 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "":&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; noVerdictBool = True&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case _:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; originalVerdictsObj.unknown += 1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Also, I've placed print statements inside each "case" section and the interactions do indeed enter into each section and thus is doing the add 1 increment to the instance variables. &amp;nbsp;Point here is that I've verified the flow is entering into the correct section.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 13:55:05 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951478#M387</guid>
      <dc:creator>dalthami</dc:creator>
      <dc:date>2023-10-31T13:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951501#M388</link>
      <description>&lt;P&gt;Ha! No worries, so the&amp;nbsp;&lt;SPAN&gt;problem isnt with the matching logic then.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;I guess that the problem its not assigning the updated values of the instance variables back to the originalVerdictsObj object?&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Example if incrementing the phishing counter, but&amp;nbsp; not assigning the updated value back to the originalVerdictsObj object. I _think_&amp;nbsp; &amp;nbsp;you can&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;assign the updated value back to the originalVerdictsObj object.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Can you try...&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;match originalVerdict:
    case "phishing":
        originalVerdictsObj.phishing += 1
        originalVerdictsObj = originalVerdictsObj&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;So from the above block you did, it would be (guessing here, i am not able to try this)&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;originalVerdict = verdict["originalVerdict"]
if bool(originalVerdict):
    match originalVerdict:
        case "phishing":
            originalVerdictsObj.phishing += 1
            originalVerdictsObj = originalVerdictsObj
        case "bec":
            originalVerdictsObj.bec += 1
            originalVerdictsObj = originalVerdictsObj
        case "scam":
            originalVerdictsObj.scam += 1
            originalVerdictsObj = originalVerdictsObj
        case "malicious":
            originalVerdictsObj.malicious += 1
            originalVerdictsObj = originalVerdictsObj
        case "spam":
            originalVerdictsObj.spam += 1
            originalVerdictsObj = originalVerdictsObj
        case "graymail":
            originalVerdictsObj.graymail += 1
            originalVerdictsObj = originalVerdictsObj
        case "":
            noVerdictBool = True
        case _:
            originalVerdictsObj.unknown += 1
            originalVerdictsObj = originalVerdictsObj&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;I think then the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;code will assign the updated values of the instance variables back to the originalVerdictsObj object, and the originalVerdictsObj object will keep the updated values.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Fingers crossed! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 14:22:08 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951501#M388</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2023-10-31T14:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951506#M389</link>
      <description>&lt;P&gt;Hi, if&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/352839"&gt;@bigevilbeard&lt;/a&gt;&amp;nbsp;suggestion is not working, can you post the complete code?&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 14:26:17 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951506#M389</guid>
      <dc:creator>Marcel Zehnder</dc:creator>
      <dc:date>2023-10-31T14:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951509#M390</link>
      <description>&lt;P&gt;Woot big dawg&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/293649"&gt;@Marcel Zehnder&lt;/a&gt;&amp;nbsp;in the house!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 14:28:58 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951509#M390</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2023-10-31T14:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951518#M391</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I need to work on my rankings &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 14:38:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951518#M391</guid>
      <dc:creator>Marcel Zehnder</dc:creator>
      <dc:date>2023-10-31T14:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951609#M392</link>
      <description>&lt;P&gt;Thank you very much for thinking about this and trying but that did not work. &amp;nbsp;I'm going to upload the script but it won't have the credentials for the API to work. &amp;nbsp;Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 17:19:00 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951609#M392</guid>
      <dc:creator>dalthami</dc:creator>
      <dc:date>2023-10-31T17:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951610#M393</link>
      <description>&lt;P&gt;Yes. &amp;nbsp;I'll update the complete code (without API credentials).&lt;/P&gt;
&lt;P&gt;Thank you for looking at this. &amp;nbsp;I can flip the code to use a dictionary to store the data but I'd much rather keep it with a class object. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 17:20:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951610#M393</guid>
      <dc:creator>dalthami</dc:creator>
      <dc:date>2023-10-31T17:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951612#M394</link>
      <description>&lt;P&gt;I've tried to upload a zip version of the .py. &amp;nbsp;Then tried the actual .py text file. &amp;nbsp;Then renamed the .py to .txt and none of those could be uploaded here. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 17:24:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951612#M394</guid>
      <dc:creator>dalthami</dc:creator>
      <dc:date>2023-10-31T17:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951657#M395</link>
      <description>&lt;P&gt;Best to use GitHub imo or just post in the code block format here&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 19:06:36 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4951657#M395</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2023-10-31T19:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4952738#M396</link>
      <description>&lt;P&gt;I finally figured it out.&amp;nbsp; It was a naming issue -- the Class and scope had nothing to do with it.&amp;nbsp; Resolved.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 16:02:44 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4952738#M396</guid>
      <dc:creator>dalthami</dc:creator>
      <dc:date>2023-11-02T16:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4952739#M397</link>
      <description>&lt;P&gt;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/91359"&gt;@dalthami&lt;/a&gt;&amp;nbsp;Congrats!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 16:03:47 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4952739#M397</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2023-11-02T16:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4953014#M398</link>
      <description>&lt;P&gt;just the naming convention!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 05:23:20 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4953014#M398</guid>
      <dc:creator>divitgupta</dc:creator>
      <dc:date>2023-11-03T05:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Scope of Class Obj in Python</title>
      <link>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4953070#M399</link>
      <description>&lt;P&gt;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/91359"&gt;@dalthami&lt;/a&gt;&amp;nbsp;: Good job!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 07:09:35 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/scope-of-class-obj-in-python/m-p/4953070#M399</guid>
      <dc:creator>Marcel Zehnder</dc:creator>
      <dc:date>2023-11-03T07:09:35Z</dc:date>
    </item>
  </channel>
</rss>

