-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilesys.py
52 lines (42 loc) · 938 Bytes
/
filesys.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
__author__ = 'jszheng'
import os
import sys
import pathlib
from pathlib import Path
import os.path
import glob
import tempfile
lorem = '''this is a very long
long long long
long long lon
test'''
def make_tempfile():
fd, temp_file_name = tempfile.mkdtemp()
os.close(fd)
f = open(temp_file_name, 'wt')
try:
f.write(lorem)
finally:
f.close()
return temp_file_name
def cleanup(filename):
os.unlink(filename)
if __name__ == '__main__':
print(os.name)
# using pathlib
print(Path.cwd())
p1 = Path('.')
print(p1)
print(p1.stat())
print(p1.resolve())
for file in sorted(p1.glob("*.py")):
print(file)
# using os.path
print(os.path.abspath('.'))
for name in glob.glob('*.py'):
print(name)
with open(sys.argv[0], 'r') as file:
for line in file:
print(line)
usrinput = sys.stdin.readline()
print(usrinput)