From e4755101bc8a55036895a33687a1d9f6bacde9e0 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 14 Apr 2024 16:26:39 +0800 Subject: [PATCH] Update precompile.md --- docs/features/precompile.md | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/docs/features/precompile.md b/docs/features/precompile.md index ee9a6479..b249d5ff 100644 --- a/docs/features/precompile.md +++ b/docs/features/precompile.md @@ -123,14 +123,10 @@ You can use this snnipet to convert every python file in a directory into precom ```python # precompile.py -import sys -import os - -count = 0 +import sys, os def precompile(filepath: str): - global count - ++count + """Precompile a python file inplace""" with open(filepath, 'r') as f: source = f.read() source = compile(source, filepath, 'exec') @@ -138,16 +134,11 @@ def precompile(filepath: str): f.write(source) def traverse(root: str): + """Traverse a directory and precompile every python file""" for entry in os.listdir(root): entrypath = os.path.join(root, entry) if os.path.isdir(entrypath): traverse(entrypath) elif entrypath.endswith(".py"): precompile(entrypath) - -traverse(sys.argv[2]) ``` -```bash -pkpy.exe precompile.py ./path/to/directory -``` -