Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -40,18 +40,17 @@ import builtins
|
|
40 |
# Global counter for file openings
|
41 |
file_open_count = 0
|
42 |
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
original_open = builtins.open
|
45 |
|
46 |
def custom_open(*args, **kwargs):
|
47 |
-
global file_open_count
|
48 |
-
# The first argument is usually the file name/path
|
49 |
file_name = args[0] if args else kwargs.get('file', 'Unknown')
|
50 |
-
|
51 |
-
if 'r' in args or kwargs.get('mode', 'r').startswith('r'):
|
52 |
-
file_open_count += 1
|
53 |
-
print(f"File '{file_name}' opened for reading. Total count: {file_open_count}")
|
54 |
-
|
55 |
return original_open(*args, **kwargs)
|
56 |
|
57 |
builtins.open = custom_open
|
|
|
40 |
# Global counter for file openings
|
41 |
file_open_count = 0
|
42 |
|
43 |
+
def log_file_access(file_name):
|
44 |
+
global file_open_count
|
45 |
+
file_open_count += 1
|
46 |
+
print(f"File '{file_name}' opened for reading. Total count: {file_open_count}")
|
47 |
+
|
48 |
+
# Patch built-in open
|
49 |
original_open = builtins.open
|
50 |
|
51 |
def custom_open(*args, **kwargs):
|
|
|
|
|
52 |
file_name = args[0] if args else kwargs.get('file', 'Unknown')
|
53 |
+
log_file_access(file_name)
|
|
|
|
|
|
|
|
|
54 |
return original_open(*args, **kwargs)
|
55 |
|
56 |
builtins.open = custom_open
|