Apr-28-2018, 02:10 PM
Make sure it only open
Example make a couple of files and extract number:
.txt
file and '.'
you run in folder with files or specify a path.Example make a couple of files and extract number:
from pathlib import Path import re current_dir = Path(".") lst = [] for obj in current_dir.iterdir(): if obj.is_file() and obj.suffix.endswith('.txt'): with open(obj) as f: lst.append(re.search(r'\d\.\d\s(-\d.\d+)', f.read()).group(1))
Output:>>> lst
['-2.868', '-9.999']
>>> [float(i) for i in lst]
[-2.868, -9.999]