赞
踩
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
import os
path = '/home/brainiac/Documents/csdn/hello\_world.py'
file_name = os.path.abspath(path)
print(file_name)
C.
import os
path = '/home/brainiac/Documents/csdn/hello\_world.py'
file_name = os.path.basename(path)
print(file_name)
D.
import os
path = '/home/brainiac/Documents/csdn/hello\_world.py'
file_name = os.path.splitext(path)[-1]
print(file_name)
正确答案: C
知识点描述:检测指定文件或目录是否存在。
问题描述:请从以下选项中选出可以检测 “/etc/passwd” 文件是否存在的选项:
A.
import os
exist = os.path.exists('etc/passwd')
print(exist)
B.
import os
exist = os.path.isdir('etc/passwd')
print(exist)
C.
import os
exist = os.path.isdir('/etc/passwd')
print(exist)
D.
import os
exist = os.path.isfile('/etc/passwd')
print(exist)
正确答案: D
知识点描述:获取文件系统中指定目录下的所有文件列表。
问题描述:获取 “/etc” 目录中所有 python 文件(以 “.py” 作为文件后缀)列表,请从以下选项中选出你认为正确的选项:
A.
import os
path = "/usr/lib/python3/dist-packages"
names = [name for name in os.listdir(path)]
print(names)
B.
import os
path = "/usr/lib/python3/dist-packages"
names = [name for name in os.listdir(path) if name.endswith('.py')]
print(names)
C.
import os
path = "/usr/lib/python3/dist-packages"
names = [name for name in os.listdir(path) if os.path.isfile(name) and name.endswith('.py')]
print(names)
D.
import os
path = "/usr/lib/python3/dist-packages"
names = [name for name in os.listdir(path) if name.endswith('\*.py')]
print(names)
正确答案: B
知识点描述:读写使用不同编码方式的文本文件。
问题描述:假设存在一文件 “text_1.txt”,如何向其中再添加两行新数据,请从以下选项中选出你认为正确的选项:
A.
new_line_1 = "New line 1"
new_line_2 = "New line 2"
with open('text\_1.txt', 'rt') as f:
f.write(new_line_1+'\n')
f.write(new_line_2+'\n')
B.
new_line_1 = "New line 1"
new_line_2 = "New line 2"
with open('text\_1.txt', 'at') as f:
f.write(new_line_1)
f.write(new_line_2)
C.
new_line_1 = "New line 1"
new_line_2 = "New line 2"
with open('text\_1.txt', 'wt') as f:
f.write(new_line_1+'\n')
f.write(new_line_2+'\n')
D.
new_line_1 = "New line 1"
new_line_2 = "New line 2"
with open('text\_1.txt', 'at') as f:
f.write(new_line_1+'\n')
f.write(new_line_2+'\n')
正确答案: D
知识点描述:将 print() 函数的输出重定向到指定日志文件中。
问题描述:将当前时间写入日志文件 “log.txt” 中,并记录函数执行结果,请从以下选项中选出你认为正确的答案:
A.
from datetime import datetime
def hello\_world(num):
return "Hello world {}!".format(num)
for i in range(10):
with open('log.txt', 'at') as f:
print(str(datetime.today()) + '\t' + hello_world(i), file=f)
B.
from datetime import datetime
def hello\_world(num):
return "Hello world {}!".format(num)
for i in range(10):
with open('log.txt', 'at') as f:
print(datetime.today() + '\t' + hello_world(i), file=f)
C.
from datetime import datetime
def hello\_world(num):
return "Hello world {}!".format(num)
for i in range(10):
with open('log.txt', 'wt') as f:
print(datetime.today() + '\t' + hello_world(i))
D.
from datetime import datetime
def hello\_world(num):
return "Hello world {}!".format(num)
for i in range(10):
with open('log.txt', 'wt') as f:
print(str(datetime.today()) + '\t' + hello_world(i), file=f)
正确答案: A
知识点描述:读写二进制文件,如图片、声音文件等。
问题描述:已知存在二进制文件 “test.bin”,如何正确向此文件追加写入文本数据,请从以下选项中选出你认为正确的答案:
A.
with open('test.bin', 'at') as f:
text = 'Hello World!\n'
f.write(text)
B.
with open('test.bin', 'wb') as f:
text = 'Hello World!\n'
f.write(text.encode('utf-8'))
C.
with open('test.bin', 'ab') as f:
text = 'Hello World!\n'
f.write(text.encode('utf-8'))
D.
with open('test.bin', 'ab') as f:
text = 'Hello World!\n'
f.write(text)
正确答案: C
知识点描述:读写 gzip 或 bz2 格式的压缩文件。
问题描述:请从以下选项中选择能够将文本文件 “text.txt” 内容写入压缩文件 “compress.gz” 的程序,且要求压缩程度最佳:
A.
import gzip
text = 'text.txt'
with gzip.open('compress.gz', 'wt', compresslevel = 9) as f:
f.write(text)
B.
import gzip
text = 'text.txt'
with gzip.open('compress.gz', 'wt', compresslevel = 0) as f:
f.write(text)
C.
import gzip
text = 'text.txt'
with open(text, 'rt') as file:
read_text = file.read()
with gzip.open('compress.gz', 'wt', compresslevel = 9) as f:
f.write(read_text)
D.
import gzip
text = 'text.txt'
with open(text, 'rt') as file:
read_text = file.read()
with gzip.open('compress.gz', 'wt', compresslevel = 0) as f:
f.write(read_text)
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
resslevel = 0) as f:
f.write(read_text)
[外链图片转存中...(img-TEyxxIcO-1715041454882)]
[外链图片转存中...(img-EwLFaOL7-1715041454883)]
[外链图片转存中...(img-hwxfPsHn-1715041454883)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。