list - Automating already existing python program -
so have program takes .txt data (set of integer numbers), makes sum every n numbers (divisions), , puts result in new list. , makes bar chart of list.
and far works fine. problem i'd make program without me having manually input number of divisions i'd make :\
i'd go through lets loop, put division 10, 11, 12... number like, , put in list, , i'd end multiple lists, can transfer excell, origin, or other program, , analysis there.
i'll put program, without plotting part, , things i've asked this:
# -*- coding: cp1250 -*- __future__ import division numpy import * matplotlib import rc matplotlib.pyplot import * import numpy np import matplotlib.pyplot plt data = loadtxt("mion-090513-1.txt", int) nuz = len(data) nsmp = 10 duz = int(nuz/nsmp) l = [] ukupni_broj=sum(data) #summed values calculation# i1 in range(0,nsmp): suma = 0 i2 in range(0,duz): suma += data[i1*duz+i2] l.append(suma) print l print 'bin number is', len(l) print 'total event number is', ukupni_broj
so i'd have nsmp in loop, values values (for instance 10-15, 20-50 in 25 interval step, , on).
is thing doable?
also there easy way of exporting results in python? searched on found nothing easy loadtxt
.
here's .txt file: https://dl.dropboxusercontent.com/u/55620972/mion-090513-1.txt
to make program easy automate , reusable, can make couple of things.
separate core functionality (e.g., computations) execution. can put computation separate module , execute form "main" script:
# my_processing.py def process_file(filename, divisions): ... # process_all.py: import my_processing filename = "..." divisions = [10, 20, 100] my_processing.process_file(filename, divisions)
this way can reuse my_processing.py
. also, habit include main
clause
def main(): .... if __name__ == "__main__" main()
if designing tool, should define command line arguments - argparse
perfect that. can use shell scripts.
Comments
Post a Comment