sort-lines
raw JSON → 0.3.0 verified Fri May 01 auth: no python
A simple command-line tool and Python library to alphabetically sort lines in files. Version 0.3.0 supports Python >=3.9. Maintenance is infrequent.
pip install sort-lines Common errors
error AttributeError: module 'sort_lines' has no attribute 'sort_lines' ↓
cause Importing the package as 'import sort_lines' instead of importing the function.
fix
Use: from sort_lines import sort_lines
error FileNotFoundError: [Errno 2] No such file or directory: '...' ↓
cause The file path provided does not exist. sort_lines does not create files, only modifies existing ones.
fix
Check that the file path is correct and the file exists before calling sort_lines.
error TypeError: sort_lines() missing 1 required positional argument: 'filename' ↓
cause Calling sort_lines without the filename argument.
fix
Provide the filename as the first argument: sort_lines('file.txt')
Warnings
gotcha The sort_lines function reads the entire file into memory. For very large files, this may cause memory issues. ↓
fix Consider using alternative tools or chunking if dealing with large files.
gotcha The library does not preserve trailing newlines behavior uniformly across platforms. Sorting may add or remove trailing newline depending on input. ↓
fix Ensure your file ends with a newline or handle manually after sorting.
gotcha There is no support for case-insensitive sorting or custom sort keys. Sorting is always lexicographic (case-sensitive). ↓
fix Preprocess lines (e.g., lowercasing) before passing to sort_lines if case-insensitive sort is needed.
Imports
- sort_lines wrong
import sort_linescorrectfrom sort_lines import sort_lines
Quickstart
from sort_lines import sort_lines
# In-place sort lines in a file
sort_lines('path/to/file.txt', in_place=True)
# Or sort and return as string
sorted_text = sort_lines('path/to/file.txt', in_place=False)
print(sorted_text)