Skip to content

[list-and-tuple] list 转 tuple + max 题目反馈 #302

Open

Description

@hehaiyang660-ui

哪一题

问题描述

Activity

  1. walter201230 commented on Sep 3, 2026

    @walter201230
    Owner

    @hehaiyang660-ui 感谢反馈,这题的判分异常已修复部署 🙏 抱歉回复晚了。

    与 #296 / #301 是同一个根因。

    根因:上一道题的变量污染了下一道题

    网站用一个 Pyodide 实例跑所有练习,但从来不清理运行环境。新手很容易把内置函数名当变量用,比如:

    max = 100        # 本意是存个最大值
    list = [1, 2, 3] # 本意是存个列表

    这一行跑过之后,max 在本次会话里就不再是那个内置函数了。等你做到后面用 max(...) 的题,连标准答案都跑不通——报的还是看不懂的错。刷新页面就恢复正常,因为实例被重建了。

    修法

    练习判分改成隔离命名空间:每道题都在全新的环境里跑,跑完即销毁,互不影响。教学代码块(那些「▶ 试运行」)保持原样共享环境,因为它们本来就设计成前后累积(前一块 import re,后一块直接用)。

    具体到 07-tuple-ops:这题要用 max(t),只要你在本次会话里的任何一道前面的题写过 max = ...,这题就必挂,且复制标准答案也一样挂。

    同一批还修了报错提示,以前只显示「代码报错:PythonError」,现在会显示真正的原因。

    麻烦强制刷新(Windows Ctrl + F5,Mac Cmd + Shift + R)再试。

  2. yhdhvyfhv commented on Sep 18, 2026

    @yhdhvyfhv

    Since the state persists in the Pyodide instance, we should implement del or import builtins; builtins.max = max in the test runner's teardown to ensure the global scope is reset between exercises.

  3. opulentgrip commented on Sep 20, 2026

    @opulentgrip

    Instead of relying on manual del or builtins restoration, we should run each test case in a clean Pyodide.runPython context or use a dedicated namespace dictionary to prevent the global scope pollution entirely.

  4. erlenekalafo commented on Oct 1, 2026

    @erlenekalafo

    Executing each exercise with a fresh globals dictionary via `pyodide.runPython(code, { globals: py

  5. emmettmorin commented on Oct 5, 2026

    @emmettmorin

    Using a dedicated namespace dictionary as suggested by opulentgrip is the right direction, but we also need to ensure that the __builtins__ reference is properly isolated to prevent students from inadvertently overriding global functions like max. Are we currently passing a custom dictionary to the globals parameter in pyodide.runPython for every execution, or is there a shared state leaking through the default context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions