-
Notifications
You must be signed in to change notification settings - Fork 105
/
storage_os.py
46 lines (34 loc) · 1.1 KB
/
storage_os.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
import lithops
from lithops.storage.cloud_proxy import open, os
def map_func(x):
with open(f'test/{x}.txt', 'w') as file:
file.write('Hello from function number {}!'.format(str(x)))
return x
if __name__ == "__main__":
# Simple file write
filepath = 'bar/foo.txt'
with open(filepath, 'w') as f:
f.write('Hello world!')
# Listing directories
dirname = os.path.dirname(filepath)
print(os.listdir(dirname))
# Read the previously created file
with open(filepath, 'r') as f:
print(f.read(6))
print(f.read())
# Remove the file
os.remove(filepath)
print(os.listdir(dirname))
# Get files that have been created in functions
fexec = lithops.FunctionExecutor()
fexec.map(map_func, [1, 2, 3, 4])
res = fexec.get_result()
with open('test/3.txt', 'r') as f:
print(f.read())
# os.walk example
with open('test/subfolder/hello.txt', 'w') as f:
f.write('hello')
for root, dirs, files in os.walk('/', topdown=True):
print(root, dirs, files)
print('-------')
os.remove('/test')