Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0562c09

Browse files
committedOct 11, 2019
第 26 天《Python 标准库之 os 模块详解》对应示例代码
1 parent c6acdbe commit 0562c09

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎day-026/__init__.py

Whitespace-only changes.

‎day-026/os_example.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
3+
# 打印系统型号
4+
print("打印系统型号")
5+
print(os.name)
6+
print()
7+
8+
# 打印环境变量
9+
print("打印环境变量")
10+
for item in os.environ:
11+
print(item, ": ", os.environ[item])
12+
print()
13+
14+
# 获取当前目录下全部文件名的函数
15+
def get_filelists(file_dir='.'):
16+
list_directory = os.listdir(file_dir)
17+
filelists = []
18+
for directory in list_directory:
19+
# os.path 模块稍后会讲到
20+
if(os.path.isfile(directory)):
21+
filelists.append(directory)
22+
return filelists

0 commit comments

Comments
 (0)
Please sign in to comment.