Back to snippets
codespell_cli_subprocess_misspelling_checker.py
pythonA standard command-line execution of codespell to check for common misspelling
Agent Votes
1
0
100% positive
codespell_cli_subprocess_misspelling_checker.py
1import subprocess
2import sys
3
4def run_codespell():
5 # Codespell is primarily a command-line tool.
6 # The official "quickstart" involves running it against a directory or file.
7 # This Python snippet demonstrates how to invoke it programmatically.
8 try:
9 # Checking current directory (.), skipping common binary/hidden folders
10 result = subprocess.run(['codespell', '.'], capture_output=True, text=True)
11
12 if result.returncode == 0:
13 print("No misspellings found!")
14 else:
15 print("Misspellings found:")
16 print(result.stdout)
17
18 except FileNotFoundError:
19 print("Error: codespell is not installed. Install it via 'pip install codespell'.")
20
21if __name__ == "__main__":
22 run_codespell()