Update tools.py
Browse files
tools.py
CHANGED
|
@@ -28,18 +28,18 @@ class read_python_file(Tool):
|
|
| 28 |
output_type = "string"
|
| 29 |
|
| 30 |
def forward(self, file_name):
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
class read_excel_file(Tool):
|
| 45 |
name = "reader_excel"
|
|
@@ -54,22 +54,22 @@ class read_excel_file(Tool):
|
|
| 54 |
|
| 55 |
def forward(self, file_name):
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
|
| 75 |
class is_commutative(Tool):
|
|
|
|
| 28 |
output_type = "string"
|
| 29 |
|
| 30 |
def forward(self, file_name):
|
| 31 |
+
try:
|
| 32 |
+
with open(file_name, "r", encoding="utf-8") as fichier:
|
| 33 |
+
contenu = fichier.read()
|
| 34 |
+
print("Contenu du fichier :\n")
|
| 35 |
+
return contenu
|
| 36 |
+
|
| 37 |
+
except FileNotFoundError:
|
| 38 |
+
print(f"Erreur : le fichier '{fichier_cible}' n'existe pas.")
|
| 39 |
+
return
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"Une erreur est survenue : {e}")
|
| 42 |
+
return
|
| 43 |
|
| 44 |
class read_excel_file(Tool):
|
| 45 |
name = "reader_excel"
|
|
|
|
| 54 |
|
| 55 |
def forward(self, file_name):
|
| 56 |
|
| 57 |
+
try:
|
| 58 |
+
# Lecture de toutes les feuilles
|
| 59 |
+
xls = pd.ExcelFile(file_name)
|
| 60 |
+
print("Sheets :", xls.sheet_names)
|
| 61 |
+
|
| 62 |
+
# Lecture d'une feuille spécifique (ici, la première)
|
| 63 |
+
df = pd.read_excel(xls, sheet_name=xls.sheet_names[0])
|
| 64 |
+
print("\nContent of the sheet :\n")
|
| 65 |
+
return df
|
| 66 |
+
|
| 67 |
+
except FileNotFoundError:
|
| 68 |
+
print(f"Erreur : le fichier '{fichier_excel}' n'existe pas.")
|
| 69 |
+
return
|
| 70 |
+
except Exception as e:
|
| 71 |
+
print(f"Une erreur est survenue : {e}")
|
| 72 |
+
return
|
| 73 |
|
| 74 |
|
| 75 |
class is_commutative(Tool):
|