Das Programm nimmt als erstes Argument den Pfad zu einer Datei, die die Daten im JSON -Format enthält, die die zu verarbeitenden Daten enthält.***
import json
import sys
from typing import List, Dict, Any, Tuple
class disponibility_class:
def __init__(self):
self.sessions = []
def load_sessions(self, file_path: str) -> List[Dict[str, Any]]:
Returns:
List[Dict[str, Any]]: Liste des objets de session
"""
try:
with open(file_path, 'r', encoding='utf-8') as file:
self.sessions = json.load(file)
return self.sessions
except FileNotFoundError:
print(f"Error: File {file_path} not found.")
return []
except json.JSONDecodeError:
print(f"Error: Invalid JSON format in {file_path}")
return []
# Example usage
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Please provide the path to the JSON file as an argument.")
sys.exit(1)
scheduler = disponibility_class()
sessions = scheduler.load_sessions(sys.argv[1])
# Print all sessions
for session in sessions:
print(f"Session: {session['session_name']}")
print(f"Teacher: {session['teacher_name']}")
print(f"Time: {session['start']} - {session['end']}")
print("-" * 40)
< /code>
Fehler: Bitte geben Sie den Pfad zur JSON -Datei als Argument an [geschlossen] ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post