Python Forum
Last Line of datafile not loading
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Last Line of datafile not loading
#1
When I run the code it dumps the 'Values.dat' file but after that when I try to load these data into a variable (named c) so that I can proceed into further calculation....the variable c is loading all data except the last line.

fs=glob.glob('*all_strain_rate_data_files/srate*.txt')
for fil in fs:
sr=float(fil.split('srate')[1].split('.txt')[0])
xy=loadtxt(fil)
y=xy[:,1]
avg=mean(y)
n_f= open('Values.dat' , 'a')
n_f.writelines(str(sr)+'\t'+str(avg)+'\n')
n_f.close

c = loadtxt('Values.dat')
print c

The Values.dat file has the following data
0.001 -0.000476901658291
0.005 -0.000459584857803
0.01 -0.000455371401619
0.02 -0.000454457184105
0.03 -0.000363427058283
0.04 -0.000425998443982
0.05 -0.000479518449808
0.06 -0.00044039265987
0.07 -0.000428992925364
0.08 -0.000479521006314
0.09 -0.000346052124686
0.5 -0.000419424003512


And the print of c ........gives
[[ 0.001 -0.0004769 ]
[ 0.005 -0.00045958]
[ 0.01 -0.00045537]
[ 0.02 -0.00045446]
[ 0.03 -0.00036343]
[ 0.04 -0.000426 ]
[ 0.05 -0.00047952]
[ 0.06 -0.00044039]
[ 0.07 -0.00042899]
[ 0.08 -0.00047952]
[ 0.09 -0.00034605]

N.B : if I do the following in another python script it it loads the last line.

c = loadtxt('Values.dat')
print c
So if it can work in separate script then why it is not reading the last line in same script ?
Reply
#2
Please Use code tags see BBCODE
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of IdnexData on datafile Led_Zeppelin 0 793 Aug-14-2022, 05:44 PM
Last Post: Led_Zeppelin
  myfile = open(datafile, 'rb') not working mford29_programmer 4 3,037 Oct-10-2019, 10:49 AM
Last Post: mford29_programmer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020