I'm having trouble writing to text file. Here's my code snippet.
ram_array= map(str, ram_value) cpu_array= map(str, cpu_value) iperf_ba_array= map(str, iperf_ba) iperf_tr_array= map(str, iperf_tr) #with open(ram, 'w') as f: #for s in ram_array: #f.write(s + '\n') #with open(cpu,'w') as f: #for s in cpu_array: #f.write(s + '\n') with open(iperf_b,'w') as f: for s in iperf_ba_array: f.write(s+'\n') f.close() with open(iperf_t,'w') as f: for s in iperf_tr_array: f.write(s+'\n') f.close() The ram and cpu both work flawlessly, however when writing to a file for iperf_ba and iperf_tr they always come out look like this:
[45947383.0, 47097609.0, 46576113.0, 47041787.0, 47297394.0] Instead of
1 2 3 They're both reading from global lists. The cpu and ram have values appended 1 by 1, but otherwise they look exactly the same pre processing.
Here's how they're made
filename= "iperfLog_2015_03_12_20:45:18_123_____tag_33120L06.csv" write_location= self.tempLocation() location=(str(write_location) + str(filename)); df = pd.read_csv(location, names=list('abcdefghi')) transfer = df.h transfer=transfer[~transfer.isnull()]#uses pandas to remove nan transfer=transfer.tolist() length= int(len(transfer)) extra= length-1 del transfer[extra] bandwidth= df.i bandwidth=bandwidth[~bandwidth.isnull()] bandwidth=bandwidth.tolist() del bandwidth[extra] iperf_tran.append(transfer) iperf_band.append(bandwidth)
with open, don't close your files - that's handled automatically.