-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileOp.py
More file actions
47 lines (34 loc) · 1.19 KB
/
fileOp.py
File metadata and controls
47 lines (34 loc) · 1.19 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
from os import getcwd
save_path = getcwd() + "\RSAfiles\\" #Save RSA files in a directory named RSAfiles created in current directory
def write_list(filename,l):
'''write a list l into file'''
completeName = save_path + filename + '.txt'
file = open(str(completeName),'w')
file.write(str(l)[1:-1])
file.close()
def read_list(filename):
'''return data from file read as list, READS ONLY INTEGERS'''
completeName = save_path + filename + '.txt'
file = open(completeName,'r')
arr = file.read().split(',')
return (list(map(int,arr)))
def read_list_noint(filename):
'''return data from file read as list, READS NON INTEGERS'''
completeName = save_path + filename + '.txt'
file = open(completeName,'r')
arr = file.read().split(',')
return (arr)
def read_large_data(filename):
'''reads basic data from file'''
msg = ""
with open(save_path + filename + ".txt") as infile:
for line in infile:
msg += line
return (msg)
def read_binary_file(filename):
'''reads binary file'''
msg = ""
with open(save_path + filename,'rb') as infile:
for line in infile:
msg += str(line)
return (msg)