Skip to content

A SyntaxError in scripts/segmentation_train.py while using Python3.12+ #228

@qinians-cn

Description

@qinians-cn

Title: Invalid escape sequence \* in glob pattern on line 44 causes SyntaxError in Python 3.12+

Description:

On line 44, the code uses the following glob pattern:

elif any(Path(args.data_dir).glob("*\*.nii.gz")):

The string "*\*.nii.gz" contains an invalid escape sequence \*. In Python versions prior to 3.12, this would raise a DeprecationWarning, but starting in Python 3.12, it raises a SyntaxError because \* is not a valid escape sequence.

This breaks compatibility with modern Python versions.

Suggested Fix:

Use rglob for recursive matching (which is likely the intended behavior), or use forward slashes with proper glob syntax:

✅ Recommended:

elif any(Path(args.data_dir).rglob("*.nii.gz")):

Alternatively (for one-level subdirectories only):

elif any(Path(args.data_dir).glob("*/*.nii.gz")):

Using raw strings (e.g., r"*\*.nii.gz") is not advised here because backslashes are not standard in glob patterns—forward slashes work cross-platform with pathlib.

Please update the pattern to ensure compatibility and correctness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions