9.9. Accessing files on disk#
9.9.1. Loading a user-made library from disk#
The library file is located in the same folder as the notebook and imported as in any other python source code
from myrand import generate_TCL_ms
from stats import stats
mean = 0.
sigma = 2.5
N_events = 1000
N_TCLsampling = 10
randlist = generate_TCL_ms (mean, sigma, N_events, N_TCLsampling)
print ('generated ', len (randlist), 'events')
mystats = stats (randlist)
print ('mean: ', mystats.mean (), '\u00B1', mystats.sigma_mean ())
print ('sigma: ', mystats.sigma ())
generated 1000 events
mean: 0.0534811198074129 ± 0.07805743137831431
sigma: 2.468392714577696
with open ('sample.txt', 'w') as output_file :
for item in randlist:
# write each item on a new line
output_file.write (str (item) + '\n')
with open ('sample.txt') as input_file :
sample = [float (x) for x in input_file.readlines()]
print ('read ', len (sample), 'events')
read 1000 events