source: python/aubio/txtfile.py @ b12c438

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since b12c438 was 366f811, checked in by Paul Brossier <piem@altern.org>, 18 years ago

add support for text file from stdin
add support for text file from stdin

  • Property mode set to 100644
File size: 1.5 KB
Line 
1"""Copyright (C) 2004 Paul Brossier <piem@altern.org>
2print aubio.__LICENSE__ for the terms of use
3"""
4
5__LICENSE__ = """\
6     Copyright (C) 2004 Paul Brossier <piem@altern.org>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21"""           
22
23def read_datafile(filename,depth=-1):
24    """read list data from a text file (columns of float)"""
25    if filename == '--' or filename == '-':
26        import sys
27        fres = sys.stdin
28    else:
29        fres = open(filename,'ro')
30    l = []
31    while 1:
32        tmp = fres.readline()
33        if not tmp : break
34        else: tmp = tmp.split()
35        if depth > 0:
36            for i in range(min(depth,len(tmp))):
37                tmp[i] = float(tmp[i])
38            l.append(tmp)
39        elif depth == 0:
40            l.append(float(tmp[0]))
41        else:
42            for i in range(len(tmp)):
43                tmp[i] = float(tmp[i])
44            l.append(tmp)
45    return l
46
Note: See TracBrowser for help on using the repository browser.