-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypecasts.py
46 lines (35 loc) · 1.22 KB
/
typecasts.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
class TypeCasts:
@staticmethod
def convert_string_to_unicode_list(text):
unicode_a = []
for char in list(text):
# echar = char.encode('UTF-16')
ordinal = ord(char)
unicode_a.append(ordinal)
return unicode_a
@staticmethod
def convert_unicodelist_to_string(u_list):
text = ""
for number in list(u_list):
# echar = char.encode('UTF-16')
character = chr(number)
text += character
return text
@staticmethod
def round_to_int(value):
return int(round(value))
@staticmethod
def tuple_to_string(input_tuple, none_replacement=True, none_replacer_char='¦'):
val_lst = list(input_tuple)
final_string = TypeCasts.list_to_string(val_lst, none_replacement, none_replacer_char)
return final_string
@staticmethod
def list_to_string(input_list, none_replacement=True, none_replacer_char='¦'):
final_string = ""
for value in input_list:
if none_replacement:
if value == None:
final_string += none_replacer_char
continue
final_string += value
return final_string