Skip to content

Commit 2663ced

Browse files
authored
fix: escape Windows paths in STARTUP_CODE string formatting
When running on Windows systems, the STARTUP_CODE template's __file__ assignment could fail due to unescaped backslashes in the Windows path. This occurs when formatting the path string into STARTUP_CODE, as Windows paths (e.g., "C:\Users\...") contain backslashes that need proper escaping in Python strings. The fix uses Path.as_posix() to convert Windows backslashes to forward slashes, which Python handles correctly across all operating systems. This ensures the path string is properly escaped when inserted into the STARTUP_CODE template. Technical details: - Uses existing pathlib.Path object's as_posix() method - Converts "C:\path\to\file" to "C:/path/to/file" - Maintains cross-platform compatibility - Fixes string formatting issues without changing functionality
1 parent 8915c48 commit 2663ced

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • py5_resources/py5_module/py5_tools/live_coding

py5_resources/py5_module/py5_tools/live_coding/syncing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
def init_namespace(filename, global_namespace):
5656
global_namespace.clear()
57-
exec(STARTUP_CODE.format(Path(filename).absolute()), global_namespace)
57+
exec(STARTUP_CODE.format(Path(filename).absolute().as_posix()), global_namespace)
5858

5959

6060
def is_subdirectory(d, f):

0 commit comments

Comments
 (0)