-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariabletypefunctions.py
More file actions
39 lines (33 loc) · 1.12 KB
/
variabletypefunctions.py
File metadata and controls
39 lines (33 loc) · 1.12 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
# This code is licensed under the MIT License, view the file "LICENSE" or go to...
# https://github.com/EliStillCantCode/VariableTypeFunctions/blob/master/LICENSE
# ...to see restrictions and permissions
def changetype(input, convert):
try:
convert(input)
except:
return "Input failed to convert."
else:
return convert(input)
def checktype(input, check):
return type(input) is check
def findtype(input):
conversions = {
"<class 'str'>" : 'str',
"<class 'int'>" : 'int',
"<class 'float'>" : 'float',
"<class 'complex'>" : 'complex',
"<class 'list'>" : 'list',
"<class 'tuple'>" : 'tuple',
"<class 'range'>" : 'range',
"<class 'dict'>" : 'dict',
"<class 'set'>" : 'set',
"<class 'frozenset'>" : 'frozenset',
"<class 'bytes'>" : 'bytes',
"<class 'bytearray'>" : 'bytearray',
"<class 'memoryview'>" : 'memoryview',
"<class 'bool'>" : 'bool',
"<class 'None'>" : 'None',
}
return conversions[str(type(input))]
def checktypenot(input, check):
return type(input) is not check