forked from johnzero7/XNALaraMesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ascii_ops.py
64 lines (47 loc) · 1.26 KB
/
ascii_ops.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# <pep8 compliant>
"""ASCII operations module."""
def readline(file):
"""Read a line and strip spaces."""
line = file.readline()
line = line.strip()
return line
def getFloat(value):
"""Read value and returns a float. If error return NaN."""
if value:
try:
return float(value)
except ValueError:
return float('NaN')
return value
def getInt(value):
"""Read value and returns a int. If error return None."""
try:
return int(value)
except ValueError:
return None
def ignoreComment(line):
"""Read line. Ignore comment."""
line = line.replace('#', ' ')
line = line.split()[0]
return line
def ignoreStringComment(line):
"""Read line. Ignore comment."""
line = line.split('#')[0].strip()
return line
def readInt(file):
"""Read line. Return Int."""
line = readline(file)
value = ignoreComment(line)
number = getInt(value)
return number
def readString(file):
"""Read line. Ignore Comments."""
# String Lenght
line = readline(file)
string = ignoreStringComment(line)
return string
def splitValues(line):
"""Read line. Return value list."""
line = line.replace('#', ' ')
values = line.split()
return values