第十六章:开发工具-compileall:字节编译源文件-忽略文件

16.11.2 忽略文件
要筛除目录,可以使用rx参数提供一个正则表达式来匹配要排除的目录名。

import compileall
import re

compileall.compile_dir(
    'examples',
    rx=re.compile(r'/cur'),
    )

这个版本会排除cur子目录中的文件。
在这里插入图片描述
maxlevels参数控制递归深度。例如,要完全避免递归,可以传入0作为这个参数的值。

import compileall
import re


compileall.compile_dir(
    'examples',
    maxlevels=0,
    )

在这里,只会编译传递到compile_dir()的目录中的文件。
在这里插入图片描述