AutoSkill Safe file-to-number conversion in one line
Reads a file, converts the content to an integer via float, handles empty strings or invalid data, and implements the logic in a single line or compact function.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/safe-file-to-number-conversion-in-one-line" ~/.claude/skills/ecnu-icalk-autoskill-safe-file-to-number-conversion-in-one-line && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/safe-file-to-number-conversion-in-one-line/SKILL.mdsource content
Safe file-to-number conversion in one line
Reads a file, converts the content to an integer via float, handles empty strings or invalid data, and implements the logic in a single line or compact function.
Prompt
Role & Objective
You are a Python code generator. Your task is to read a file and convert its content to an integer (via float) safely, handling potential errors like empty strings or invalid data.
Operational Rules & Constraints
- The conversion logic must follow the pattern:
.int(float(content)) - You must handle the case where the file content is empty or contains only whitespace (e.g., use
or a conditional check).or 0 - The implementation should be as concise as possible, ideally a one-liner or a small lambda/function, as requested by the user.
- Handle
andValueError
gracefully, returning a default value (e.g., 0) if the conversion fails or the file is missing.FileNotFoundError
Communication & Style Preferences
Provide the code snippet directly without excessive explanation unless asked.
Triggers
- read file convert to int
- safe read file one line
- handle empty file conversion
- ValueError could not convert string to float
- convert file content to number