用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/HKUDS/OpenSpace --skill document-python-direct-exec命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification
Audio production with diagnostic analysis, timecode parsing from documents, and verified export workflow
Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies
基于 SOC 职业分类
| name | document-python-direct-exec |
| description | Use direct Python execution for reliable spreadsheet and document/PDF generation operations |
Use direct run_shell with Python scripts for structured document operations when:
The shell_agent tool can:
Direct run_shell with Python is more reliable because it:
.py files first avoids shell_agent parsing issues with heredocsFor complex multi-line scripts, especially when using shell_agent as executor:
# Step 1: Write the Python script to a file
cat > process_document.py << 'EOF'
# Your document/spreadsheet code here
EOF
# Step 2: Execute the script
python3 process_document.py
For short, simple scripts when NOT using shell_agent as the executor:
python3 << 'EOF'
# Your code here
EOF
import pandas as pd
# Load data from specific sheet
df = pd.read_excel('input.xlsx', sheet_name='Revenue')
# Apply transformations
df['Net_Revenue'] = df['Gross_Revenue'] * (1 - df['Tax_Rate'])
# Save results
df.to_excel('output.xlsx', index=False, sheet_name='Processed')
from openpyxl import load_workbook
wb = load_workbook('tour_data.xlsx')
# Iterate through sheets
for sheet_name in wb.sheetnames:
ws = wb[sheet_name]
# Apply formatting or calculations
for row in ws.iter_rows(min_row=2, max_col=5):
# Process cells
pass
wb.save('tour_data_processed.xlsx')
from openpyxl import load_workbook
from openpyxl.styles import Font, PatternFill, Alignment
wb = load_workbook('report.xlsx')
ws = wb.active
# Apply header styling
header_fill = PatternFill(start_color='4472C4', fill_type='solid')
header_font = Font(bold=True, color='FFFFFF')
for cell in ws[1]:
cell.fill = header_fill
cell.font = header_font
cell.alignment = Alignment(horizontal='center')
wb.save('report_formatted.xlsx')
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
def create_checklist(pdf_path, items):
c = canvas.Canvas(pdf_path, pagesize=letter)
width, height = letter
# Title
c.setFont("Helvetica-Bold", 16)
c.drawString(1*inch, height - 1*inch, "Safety Checklist")
# Checklist items
c.setFont("Helvetica", 12)
y_position = height - 1.5*inch
for i, item in enumerate(items, 1):
checkbox_x = 1*inch
text_x = 1.3*inch
c.drawString(checkbox_x, y_position, "☐") # Empty checkbox
c.drawString(text_x, y_position, f"{i}. {item}")
y_position -= 0.3*inch
# New page if needed
if y_position < 1*inch:
c.showPage()
y_position = height - 1*inch
c.save()
print(f"Created checklist: {pdf_path}")
# Usage
items = [
"Verify equipment is powered off",
"Check safety gear is available",
"Inspect work area for hazards",
"Confirm emergency contacts are posted"
]
create_checklist('safety_checklist.pdf', items)
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
def create_report(pdf_path, title, data, column_headers):
doc = SimpleDocTemplate(pdf_path, pagesize=letter,
rightMargin=0.75*inch, leftMargin=0.75*inch,
topMargin=0.75*inch, bottomMargin=0.75*inch)
elements = []
styles = getSampleStyleSheet()
# Title
title_style = ParagraphStyle('CustomTitle', parent=styles['Heading1'],
fontSize=18, spaceAfter=30, alignment=1)
elements.append(Paragraph(title, title_style))
elements.append(Spacer(1, 0.25*inch))
# Table
table_data = [column_headers] + data
table = Table(table_data, colWidths=[2*inch, 1.5*inch, 1.5*inch])
# Table styling
table.setStyle(TableStyle([
('BACKGROUND', (0, 0), (-1, 0), colors.HexColor('#4472C4')),
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
('ALIGN', (, ), (-, -), ),
(, (, ), (-, ), ),
(, (, ), (-, ), ),
(, (, ), (-, ), ),
(, (, ), (-, -), [colors.white, colors.HexColor()]),
(, (, ), (-, -), , colors.grey),
]))
elements.append(table)
doc.build(elements)
()
headers = [, , ]
data = [
[, , ],
[, , ],
[, , ]
]
create_report(, , data, headers)
from fpdf import FPDF
class PDF(FPDF):
def header(self):
self.set_font('Arial', 'B', 15)
self.cell(0, 10, 'Project Documentation', 0, 1, 'C')
self.ln(10)
def footer(self):
self.set_y(-15)
self.set_font('Arial', 'I', 8)
self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')
def create_document(pdf_path, title, sections):
pdf = PDF()
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
pdf.cell(0, 10, title, 0, 1, 'L')
pdf.ln(5)
pdf.set_font('Arial', '', 12)
section sections:
pdf.set_font(, , )
pdf.cell(, , section[], , )
pdf.set_font(, , )
pdf.multi_cell(, , section[])
pdf.ln()
pdf.output(pdf_path)
()
sections = [
{: , : },
{: , : },
{: , : }
]
create_document(, , sections)
import sys
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
try:
c = canvas.Canvas('output.pdf', pagesize=letter)
# Your document operations here
c.drawString(100, 750, "Document content")
c.save()
print("Success: PDF created")
except Exception as e:
print(f"Error: {str(e)}", file=sys.stderr)
sys.exit(1)
.py file first, then execute via run_shellpandoc for document conversion)| Library | Best For |
|---|---|
openpyxl | Reading/writing .xlsx files, formatting, formulas |
pandas | Data manipulation, analysis, merging datasets |
xlrd | Reading older .xls files (read-only) |
xlsxwriter | Creating new .xlsx files with advanced formatting |
reportlab | Professional PDF generation with precise layout control |
fpdf | Simple PDF creation, easier learning curve |
python-docx | Creating and editing Word documents |
weasyprint | HTML/CSS to PDF conversion |
Issue: Heredoc syntax fails with 'unknown error' when using shell_agent
.py file first, then execute it with python3 script.py. This pattern is significantly more reliable than inline heredoc execution when shell_agent is the executor.Issue: FileNotFoundError
os.getcwd() to confirm current directory if needed.Issue: PermissionError
ls -la.Issue: ModuleNotFoundError
pip install reportlab openpyxl pandas. Some environments may need pip3 instead.Issue: MemoryError on large files
chunksize parameter. For PDFs, create multi-page documents instead of single massive pages.Issue: Formatting not applying (spreadsheets)
.copy() for style objects to avoid reference issues.Issue: PDF text rendering incorrectly
Issue: PDF layout breaks across pages
showPage() when needed.| Need | Recommended Library |
|---|---|
| Data analysis, calculations | pandas + Excel output |
| Complex cell formatting | openpyxl |
| Professional reports with tables | reportlab (PDF) |
| Simple checklists, forms | fpdf or reportlab |
| Word document output | python-docx |
| HTML to PDF | weasyprint |
| Both data + formatted output | Generate data with pandas, format with reportlab |