Utility Functions¶
The utility
module provides various utility functions for string manipulation, file operations, and system information.
Module Reference¶
demoprogram.utility
¶
Utility functions for the demo program package.
Functions¶
get_file_size(file_path: str) -> int
¶
Get the size of a file in bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path to the file |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
File size in bytes |
format_bytes(bytes_size: int) -> str
¶
Format bytes into human-readable format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bytes_size
|
int
|
Size in bytes |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted string (e.g., "1.5 MB") |
Source code in demoprogram/utility.py
reverse_string(text: str) -> str
¶
Reverse a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
Input string |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Reversed string |
is_palindrome(text: str) -> bool
¶
Check if a string is a palindrome.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
Input string |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if palindrome, False otherwise |
Source code in demoprogram/utility.py
count_words(text: str) -> int
¶
Count the number of words in a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
Input string |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of words |
get_system_info() -> dict
¶
Get basic system information.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
System information |