core.delete¶
Functions¶
delete_empty_lines ¶
Remove all empty lines from a list of strings.
Filters out lines that are empty or contain only whitespace characters, returning a new list with only non-empty lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_list | list[str] | List of strings to filter. | required |
Returns:
| Type | Description |
|---|---|
list[str] | List[str]: New list containing only non-empty lines. |
Examples:
>>> delete_empty_lines(["hello", "", "world", " ", "test"])
['hello', 'world', 'test']
>>> delete_empty_lines([])
[]
Source code in pyadvtools/core/delete.py
delete_empty_lines_first_occur ¶
Remove empty lines from the beginning of a list.
Removes consecutive empty lines from the start of the list until the first non-empty line is encountered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_list | list[str] | List of strings to process. | required |
Returns:
| Type | Description |
|---|---|
list[str] | List[str]: List with leading empty lines removed, or empty list if all lines are empty. |
Examples:
>>> delete_empty_lines_first_occur(["", "", "hello", "world"])
['hello', 'world']
>>> delete_empty_lines_first_occur(["", "", ""])
[]
>>> delete_empty_lines_first_occur(["hello", "world"])
['hello', 'world']
Source code in pyadvtools/core/delete.py
delete_empty_lines_last_occur_add_new_line ¶
Remove trailing empty lines and ensure proper newline ending.
Removes empty lines from the end of the list and ensures the last line ends with a newline character.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_list | list[str] | List of strings to process. | required |
Returns:
| Type | Description |
|---|---|
list[str] | List[str]: List with trailing empty lines removed and proper newline ending added to the last line. |
Examples:
>>> result = delete_empty_lines_last_occur_add_new_line(["hello", "world", "", ""])
>>> result
['hello', 'world\n']
Source code in pyadvtools/core/delete.py
delete_files ¶
Delete files with specified extensions from a directory.
Removes all files in the given directory that have any of the specified file extensions. The function processes each file in the directory and deletes those matching the extension criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_storage | str | Directory path containing files to potentially delete. | required |
extensions | list[str] | List of file extensions to match (e.g., ['.txt', '.log']). Extensions should include the dot prefix. | required |
Returns:
| Name | Type | Description |
|---|---|---|
None | None | Files are deleted in place, no return value. |
Note
This function permanently deletes files. Use with caution.
Examples:
Source code in pyadvtools/core/delete.py
delete_python_cache ¶
Recursively delete all pycache directories.
Walks through the directory tree starting from the given root path and removes all pycache directories and their contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_root | str | Root directory path to start the search from. | required |
Returns:
| Name | Type | Description |
|---|---|---|
None | None | pycache directories are deleted in place. |
Note
This function permanently deletes directories. Use with caution.
Examples:
>>> delete_python_cache("/path/to/project")
# Removes all __pycache__ directories under /path/to/project
Source code in pyadvtools/core/delete.py
delete_redundant_elements ¶
Remove duplicate elements while preserving order.
Removes duplicate elements from the list while maintaining the original order of first occurrence. Also strips whitespace from each element and filters out empty elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_list | list[str] | List of strings to deduplicate. | required |
Returns:
| Type | Description |
|---|---|
list[str] | List[str]: New list with duplicates removed, whitespace stripped, and empty elements filtered out, preserving original order. |
Examples:
>>> delete_redundant_elements(["a", "b", "a", "c", " b ", ""])
['a', 'b', 'c']
>>> delete_redundant_elements(["x", "x", "x"])
['x']