Bonjour,
j'utilise PyCharm pour débugger un début de code.
je cherche à ouvrir un fichier qui a un nom variableet qui est stocké à un endroit variable égalementall_fileset qui n'est pas forcément celui où est exécuté le code.file
Ma question est donc comment puis-je ouvrir un ficher en lecture a partir d'un chemin donnée par une variable (ligne 14 du code)?
Voilà.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 encoding="utf8" import glob from matplotlib import pyplot as plt # plots from numpy import genfromtxt # find files file="G:\Document\Test\ANY044" all_files = glob.glob(file + "/*.csv") if (len(all_files)) == 0: raise FileNotFoundError("No files found in directory : " + file) print("Import the file: " + str(all_files)) g = open(all_files,'r') my_data = genfromtxt(g, delimiter=',') # create numpy 3D matrix # my_data = np.moveaxis(my_data, 1, 1) # create meta variables Nx = my_data.shape[1] Ny = my_data.shape[0] plt.figure() plt.imshow(my_data, cmap='jet') #extent=[min(x), max(x), min(y), max(y)]) plt.xlabel("[cm]") plt.ylabel("[cm]") plt.title("Power density map") cbar = plt.colorbar() cbar.set_label("[Wm^2]") plt.show()
Merci
Partager