-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeUtils.py
More file actions
116 lines (86 loc) · 1.93 KB
/
TypeUtils.py
File metadata and controls
116 lines (86 loc) · 1.93 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""
Name: TypeUtils
Purpose: Determine the data types of arguments
Dependencies: none
Version: 3.6
Author: ted.chapin
Created: 9/17/2018
"""
import datetime
import json
import os
config_file = os.path.join(os.path.dirname(__file__), "config.json")
CONFIG = json.loads(open(config_file).read()) if os.path.isfile(config_file) else {}
def main():
pass
return
def is_date(date_string, date_format):
"""
purpose:
determine if the string is a date in the specified format
arguments:
date_string: string
The value to evaluate for dateness
date_format: string
The format string to use to evaluate the date string
return value: Boolean
"""
try:
datetime.datetime.strptime(date_string, date_format)
return True
except Exception:
return False
def is_none_or_empty(arg):
"""
purpose:
check if the arg is either None or an empty string
arguments:
arg: varies
return value: Boolean
"""
try:
return arg is None or arg == ""
except Exception:
return False
def is_numeric(arg):
"""
purpose:
check if the arg is a number
arguments:
arg: varies
return value: Boolean
"""
try:
float(arg)
return True
except Exception:
return False
def is_integer(arg):
"""
purpose:
check if the arg is an integer
arguments:
arg: varies
return value: Boolean
"""
try:
return float(arg).is_integer()
except Exception:
return False
def is_string(arg):
"""
purpose:
check is the arg is a string
arguments:
arg: varies
return value: Boolean
"""
if arg is None:
return False
try:
str(arg)
return True
except Exception:
return False
if __name__ == '__main__':
main()