-
Notifications
You must be signed in to change notification settings - Fork 4
/
my_first_file.py
56 lines (39 loc) · 1.03 KB
/
my_first_file.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
""" Files examples
"""
def first():
with open('experience.txt', 'w') as f:
f.write('This is my first saved output\n')
def second():
with open('experience.txt', 'a') as f:
f.write('This is my second saved output\n')
# Let's try with some numbers:
def numbers():
l = list()
for i in range(10):
l.append(i ** i)
with open('experience.txt', 'a') as f:
for each in l:
f.write('{};'.format(str(each)))
# What have we done?
def reading():
with open('experience.txt', 'r') as f:
lida = f.read()
# print(lida)
return lida
def recover_list(li):
li = li.split('\n')
recovered = list()
for each in li[2].split(';'):
if len(each) > 0:
recovered.append(int(each))
# print(recovered)
return recovered
def sum_list(recovered):
print('A soma da lista recuperada é {:,.0f}'.format(sum(recovered)))
if __name__ == '__main__':
# first()
# second()
# numbers()
r = reading()
ll = recover_list(r)
sum_list(ll)