面试其他篇
目录:
头条面试题:https://blog.csdn.net/m0_37947204/article/details/80103151
1.1 python常见基础题
1、遍历文件夹
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#! /usr/bin/env python # -*- coding: utf-8 -*- import os rootdir = r'C:\Users\tom\Desktop\mianshi\day01' file_list = [] def bianli(f): fs = os.listdir(f) for i in fs: tmp_path = os.path.join(f,i) if not os.path.isdir(tmp_path): # 如果是文件就加入到文件列表中 file_list.append(tmp_path) else: bianli(tmp_path) # 每次都遍历从一个文件夹遍历到最高深度,然后再遍历for循环中下一个 bianli(rootdir) print file_list ''' ['C:\\Users\\tom\\Desktop\\mianshi\\day01\\test.txt', 'C:\\Users\\tom\\Desktop\\mianshi\\day01\\test01.py',] '''
111111111111