跳到正文
cccskills
免费在 GitHub 公开

fallback-python-shell

Continue file reading and data processing when execute_code_sandbox or read_file fails. This skill runs multiline Python through run_shell, with examples for text, JSON, spreadsheets, PDF and Word documents, plus basic summaries and grouped calculations.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Use run_shell with Python heredoc when execute_code_sandbox or read_file fail

集成工具Excel
查看安装方法

适用场景

  • Reading text or JSON when read_file fails
  • Inspecting Excel and CSV data through Python
  • Extracting text from PDF and Word documents
  • Continuing data analysis after sandbox execution errors

包含的文件(2)

  • SKILL.md4.0 KB
  • .skill_id35 B

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Shell-Based Python Fallback

When to Use

Use this fallback pattern when:

  • execute_code_sandbox returns 'unknown error'
  • read_file returns 'unknown error' for supported formats
  • You need to process documents, analyze data, or read files programmatically

Core Technique

Run Python code through run_shell using a heredoc. This bypasses sandbox execution issues while maintaining Python's full capabilities for file I/O and data processing.

Basic Pattern

python3 << 'EOF'
# Your Python code here
import json
import os

# Example: Read and process a file
with open('/path/to/file.txt', 'r') as f:
    content = f.read()
    print(content)
EOF

Key Syntax Points

  1. Use python3 << 'EOF' (quoted EOF prevents variable expansion in the heredoc)
  2. Indent Python code starting from column 0 (no extra indentation from shell)
  3. End with EOF on its own line with no leading/trailing whitespace
  4. Print results to stdout to capture them in the tool response

Common Use Cases

Reading Files (Fallback for read_file)

python3 << 'EOF'
import json

# Read text file
with open('document.txt', 'r') as f:
    content = f.read()
    print(content)

# Read JSON file
with open('data.json', 'r') as f:
    data = json.load(f)
    print(json.dumps(data, indent=2))
EOF

Processing Excel/CSV Files

python3 << 'EOF'
import pandas as pd

# Read Excel file
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
print(df.to_string())
print(f"Shape: {df.shape}")

# Read CSV
df = pd.read_csv('data.csv')
print(df.head(10))
EOF

Reading PDF Files

python3 << 'EOF'
import fitz  # PyMuPDF

doc = fitz.open('document.pdf')
for page_num in range(len(doc)):
    page = doc[page_num]
    text = page.get_text()
    print(f"=== Page {page_num + 1} ===")
    print(text)
doc.close()
EOF

Reading Word Documents

python3 << 'EOF'
from docx import Document

doc = Document('document.docx')
for para in doc.paragraphs:
    print(para.text)
EOF

Data Analysis

python3 << 'EOF'
import pandas as pd
import numpy as np

df = pd.read_csv('data.csv')

# Basic statistics
print(f"Shape: {df.shape}")
print(f"Columns: {list(df.columns)}")
print(df.describe())

# Filter and aggregate
result = df.groupby('category').agg({'value': 'sum'})
print(result)
EOF

Best Practices

  1. Error Handling: Wrap file operations in try/except blocks

    python3 << 'EOF'
    try:
        with open('file.txt', 'r') as f:
            content = f.read()
            print(content)
    except FileNotFoundError:
        print("ERROR: File not found")
    except Exception as e:
        print(f"ERROR: {e}")
    EOF
    
  2. Large Output: For large files, process in chunks or print summaries

    python3 << 'EOF'
    with open('large_file.csv', 'r') as f:
        for i, line in enumerate(f):
            if i < 10:
                print(line.strip())
            else:
                print("... truncated ...")
                break
    EOF
    
  3. Working Directory: Remember run_shell executes in the current working directory. Use absolute paths or ensure you're in the right directory.

  4. Multiple Steps: Chain related operations in a single heredoc rather than multiple calls

    python3 << 'EOF'
    # Do all related work in one call
    with open('input.json') as f:
        data = json.load(f)
    
    processed = [transform(x) for x in data]
    
    with open('output.json', 'w') as f:
        json.dump(processed, f)
    
    print("Processing complete")
    EOF
    

Troubleshooting

  • Module not found: Some packages may not be available. Stick to standard library or commonly pre-installed packages (pandas, numpy are often available).
  • Permission errors: Ensure files aren't in protected directories.
  • Character encoding: Specify encoding explicitly: open('file.txt', 'r', encoding='utf-8')
  • Very long code: Split into multiple heredocs or write to a temporary .py file first.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Prepare audio stems, the separate parts of a track, for mixing by matching their durations with silence, loops, or crossfades. Verify each generated and processed file before moving to the next production step.

中文简介正在准备中。当前显示英语简介。

  • Match audio parts with different durations
  • Extend drums and melodic parts using suitable methods
  • Check audio specifications before mixing
HKUDS/OpenSpace77572026年8月13日 更新

Produce audio in separate stems, meaning individual instrument tracks, and verify each output as you go. Align track lengths with silence, loops, or crossfades, then apply effects, mix a master, and package the files.

中文简介正在准备中。当前显示英语简介。

  • Align instrument tracks to a reference audio file
  • Choose how to extend tracks that are too short
  • Verify audio properties after generation and effects
HKUDS/OpenSpace77572026年8月13日 更新

Build serverless endpoints that relay external API requests for a dashboard while keeping API keys on the server. Includes Vercel examples for input checks, caching, cross-origin access, and consistent JSON responses.

中文简介正在准备中。当前显示英语简介。

  • Connect a dashboard to external APIs without exposing API keys
  • Create endpoints for stock quotes and news
  • Standardize API responses and error handling
HKUDS/OpenSpace77572026年8月13日 更新

Produce a master track and separate audio parts through a structured Python workflow. Apply filters and reverb, export WAV files with consistent settings, package them in a ZIP archive, and check that the deliverables meet the requested specifications.

中文简介正在准备中。当前显示英语简介。

  • Export a master track with separate audio parts
  • Apply filters and reverb to audio
  • Check duration and format across deliverables
HKUDS/OpenSpace77572026年8月13日 更新

Keep document creation moving when web searches and page retrieval repeatedly fail. The skill preserves the original task, uses the model’s existing knowledge, and clearly identifies information that could not be checked against external sources.

中文简介正在准备中。当前显示英语简介。

  • Continue drafting after repeated web retrieval failures
  • Preserve task requirements during network errors
  • Mark information that could not be externally verified
HKUDS/OpenSpace77572026年8月13日 更新

When Python execution repeatedly fails in execute_code_sandbox, use a file-based alternative: save the script, run it through the shell, and capture results or errors. The guidance covers paths, imports, timeouts, structured output, and optional cleanup.

中文简介正在准备中。当前显示英语简介。

  • Retry Python work through the shell after repeated sandbox failures
  • Run longer tasks with an adjusted timeout
  • Execute Python work that needs multiple files or system utilities
HKUDS/OpenSpace77572026年8月13日 更新

查看 HKUDS 的全部技能

报告此技能的问题