function has_wuxi_coding
Validates whether a filename starts with a Wuxi coding pattern consisting of dot-separated numeric segments (e.g., '2.13.4.1.2').
/tf/active/vicechatdev/mailsearch/copy_signed_documents.py
24 - 29
simple
Purpose
This function checks if a given filename begins with a specific hierarchical numbering pattern known as 'Wuxi coding', which consists of one or more numeric segments separated by dots. This pattern is commonly used in document management systems, file organization schemes, or classification systems where hierarchical numeric identifiers are prefixed to filenames. The function returns True if the pattern is found at the start of the filename, False otherwise.
Source Code
def has_wuxi_coding(filename):
"""Check if filename starts with wuxi coding pattern (e.g., '2.13.4.1.2')"""
# Look for pattern at start of filename: digits.digits.digits etc
import re
pattern = r'^\d+(?:\.\d+)+'
return bool(re.match(pattern, filename))
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
filename |
- | - | positional_or_keyword |
Parameter Details
filename: A string representing the filename to check. Expected to be a filename (with or without extension) that may or may not start with the Wuxi coding pattern. Can be a full path or just a filename. The function only checks the beginning of the string for the pattern.
Return Value
Returns a boolean value: True if the filename starts with the Wuxi coding pattern (one or more digits followed by one or more occurrences of a dot and more digits), False otherwise. The pattern must be at the very start of the filename string.
Dependencies
re
Required Imports
import re
Conditional/Optional Imports
These imports are only needed under specific conditions:
import re
Condition: imported lazily inside the function, always needed when function is called
Required (conditional)Usage Example
import re
def has_wuxi_coding(filename):
"""Check if filename starts with wuxi coding pattern (e.g., '2.13.4.1.2')"""
import re
pattern = r'^\d+(?:\.\d+)+'
return bool(re.match(pattern, filename))
# Example usage
print(has_wuxi_coding('2.13.4.1.2_document.pdf')) # True
print(has_wuxi_coding('1.2.3_report.docx')) # True
print(has_wuxi_coding('document_2.13.4.pdf')) # False
print(has_wuxi_coding('123_file.txt')) # False (needs at least one dot)
print(has_wuxi_coding('1.2')) # True
print(has_wuxi_coding('no_coding_here.txt')) # False
Best Practices
- The function expects at least two numeric segments separated by a dot (e.g., '1.2'). A single number without a dot will return False.
- The pattern only matches at the start of the filename string. If the Wuxi coding appears elsewhere in the filename, it will not be detected.
- The function does not validate the semantic correctness of the Wuxi coding scheme, only its syntactic pattern.
- Consider using os.path.basename() on full file paths before passing to this function if you only want to check the filename portion and not the directory path.
- The regex pattern allows any number of numeric segments (minimum 2), so '1.2', '1.2.3', and '1.2.3.4.5.6.7.8.9' are all valid.
- The function uses lazy import of 're' module inside the function, which is slightly less efficient if called repeatedly. Consider importing 're' at module level for better performance in production code.
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function has_wuxi_coding_v1 97.7% similar
-
function extract_document_code_v1 56.8% similar
-
function find_best_folder 56.7% similar
-
function scan_wuxi2_folder_v1 51.8% similar
-
function scan_wuxi2_folder 51.8% similar