<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Python script runs successfully in Thonny but returns NameError: name &#x27;Snowflake&#x27; isn&#x27;t defined if run from app list]]></title><description><![CDATA[<p dir="auto">I created this simple app to play with animations</p>
<pre><code class="language-python">import M5
import random

class Snowflake:
    def __init__(self):
        self.MAX_WIDTH = 320
        self.MAX_HEIGHT = 240
        self.radius = random.randint(2, 4)
        self.velocity = random.randint(2, 5)
        self.x = random.randint(0, self.MAX_WIDTH)
        self.y = random.randint(0, self.MAX_HEIGHT)
    
    def fall(self):
        self.y += self.velocity
        if self.y &gt; self.MAX_HEIGHT:
            self._reset()
    
    def _reset(self):
        self.radius = random.randint(2, 4)
        self.velocity = random.randint(2, 5)
        self.x = random.randint(0, self.MAX_WIDTH)
        self.y = 2

def setup():
    global SNOWFLAKES_COUNT
    global snow
    global circles
    
    SNOWFLAKES_COUNT = 80
    snow=[]
    circles=[]
    
    M5.begin()
    M5.Widgets.fillScreen(0x66b8f7)    
    for _ in range(SNOWFLAKES_COUNT):
        snow.append(Snowflake())
        circles.append(M5.Widgets.Circle(0, 0, 0, 0xffffff, 0xffffff))

def loop():
    M5.update()
    head = M5.Widgets.Circle(160, 144, 25, 0xffffff, 0xffffff)
    body = M5.Widgets.Circle(160, 199, 39, 0xffffff, 0xffffff)
    nose = M5.Widgets.Triangle(161, 143, 122, 150, 161, 148, 0xEA6511, 0xEA6511)
    left_eye = M5.Widgets.Circle(152, 135, 2, 0x000000, 0x000000)
    right_eye = M5.Widgets.Circle(167, 135, 2, 0x000000, 0x000000)
    for index, s in enumerate(snow):
        s.fall()
        c = circles[index]
        c.setRadius(r=s.radius)
        c.setCursor(x=s.x, y=s.y)

if __name__ == '__main__':
  try:
    setup()
    while True:
      loop()
  except (Exception, KeyboardInterrupt) as e:
    try:
      from utility import print_error_msg
      print_error_msg(e)
    except ImportError:
      print("please update to latest firmware")
</code></pre>
<p dir="auto">If i run this code from Thonny pressing the run button it works, but if i run it from the the app list, i get this error:</p>
<pre><code class="language-bash">MPY: soft reboot
       _  __ _               
 _   _(_)/ _| | _____      __
| | | | | |_| |/ _ \ \ /\ / /
| |_| | |  _| | (_) \ V  V / 
 \__,_|_|_| |_|\___/ \_/\_/  2.0.3

_click_event_handler
_click_event_handler
Traceback (most recent call last):
  File "apps/snowman.py", line 60, in &lt;module&gt;
  File "apps/snowman.py", line 40, in setup
NameError: name 'Snowflake' isn't defined

MicroPython v1.22.0-dirty on 2024-03-21; M5STACK Core2 with ESP32(SPIRAM)
Type "help()" for more information.
</code></pre>
<p dir="auto">Anyone knows the cause of this error and how to resolve it?</p>
]]></description><link>https://community.m5stack.com/topic/6302/python-script-runs-successfully-in-thonny-but-returns-nameerror-name-snowflake-isn-t-defined-if-run-from-app-list</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 23:52:37 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6302.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 04 Apr 2024 18:34:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Python script runs successfully in Thonny but returns NameError: name &#x27;Snowflake&#x27; isn&#x27;t defined if run from app list on Mon, 20 Oct 2025 21:45:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/genio" aria-label="Profile: Genio">@<bdi>Genio</bdi></a> Hi I hope you have resolved this issue! would you please share how you handle this error in the end?</p>
]]></description><link>https://community.m5stack.com/post/30070</link><guid isPermaLink="true">https://community.m5stack.com/post/30070</guid><dc:creator><![CDATA[h12616]]></dc:creator><pubDate>Mon, 20 Oct 2025 21:45:13 GMT</pubDate></item></channel></rss>