-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
36 lines (30 loc) · 869 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python -*- coding: utf-8 -*-
import fileinput
import glob
import sys
def error(message):
print >> sys.stderr, message
sys.exit()
def warning(message):
print >> sys.stderr, message
def get_input(file_pattern, encoding="utf8"):
file_list = []
if file_pattern:
file_list = glob.glob(file_pattern)
if len(file_list) == 0:
error("No input files found.")
return fileinput.input(file_list, openhook=fileinput.hook_encoded(encoding))
def str2float(string):
import numpy as np
try:
value = float(string)
if np.isnan(value):
warning("ignored value: NaN")
return None
else:
return value
except ValueError:
warning("ignored invalid literal: %s" % string)
return None
def isPython3():
return sys.version_info[0] == 3