INNER CODE UNIT · Python

_dig

simonlin1212/Vibe-Research · calc/cli.py:154

def _dig(obj, dotted: str):
    """按点路径取值:data.sz300308.qfqday;数字段当列表下标。"""
    cur = obj
    for part in [p for p in dotted.split(".") if p != ""]:
        if isinstance(cur, list):
            if not part.isdigit() or int(part) >= len(cur):
                raise ValueError(f"rows_path 段 {part!r} 不是有效列表下标")
            cur = cur[int(part)]
        elif isinstance(cur, dict):
            if part not in cur:
                raise ValueError(f"rows_path 段 {part!r} 不存在(可用键:{list(cur)[:8]})")
            cur = cur[part]
        else:
            raise ValueError(f"rows_path 在 {part!r} 处遇到非容器")
    return cur


_JSONP_RE = re.compile(r"^\s*(?:/\*\*/)?([A-Za-z_$][\w$.]*)\s*\((.*)\)\s*;?\s*$", re.S)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…