-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_lib.py
More file actions
executable file
·55 lines (49 loc) · 1.22 KB
/
os_lib.py
File metadata and controls
executable file
·55 lines (49 loc) · 1.22 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
47
48
49
50
51
52
53
54
55
"""os library
"""
import os
# os name
print(os.name)
print(os.uname())
# os environ
print(os.environ)
os.environ['TEST_VAR'] = 'python programming'
print(os.environ['TEST_VAR'])
print('TEST_VAR' in os.environ)
if 'ENV_VAR' not in os.environ:
os.environ['ENV_VAR'] = 'value'
print('add env var')
else:
print("env var exist")
# directory
print(os.listdir())
print(os.listdir('/tmp'))
print(os.listdir('..'))
os.mkdir('test') # make directory
os.rmdir('test') # remove directory
print(os.getcwd()) # current directory
os.chdir('/tmp') # change directory
print(os.getcwd())
os.makedirs('dir/test')
os.makedirs('dir/test2')
os.rename('dir', 'directory') # for file and dir
# mini project for sort videos
PATH = '.'
os.chdir(PATH)
file_number = 1
for file_ in os.listdir():
if file_.endswith('.mp4'):
os.rename(file_, f'{str(file_number)}.mp4')
file_number += 1
# permitions
os.system('touch test.txt')
FILE_NAME = 'test.txt'
if not os.access(FILE_NAME, os.W_OK):
print(f"We can't write text in {FILE_NAME}")
else:
with open(FILE_NAME, "w") as txt_file:
txt_file.write('Hello, World!')
# run system commands
os.system('clear')
os.system('ls $HOME')
os.system('echo $HOME')
os.system('ping 8.8.8.8')