Skip to content

Commit 9e9d342

Browse files
moverestJguer
authored andcommitted
chore(readme): use pathlib and iglob in multi-scan example
1 parent b6057cf commit 9e9d342

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ else:
8080
```py
8181
API_KEY = os.getenv("GG_API_KEY")
8282
client = GGClient(api_key=API_KEY)
83+
8384
# Create a list of dictionaries for scanning
84-
to_scan = []
85-
for name in glob.glob("**/*", recursive=True):
86-
with open(name) as fn:
87-
to_scan.append({"document": fn.read(), "filename": os.path.basename(name)})
85+
file_paths = (pathlib.Path(name) for name in glob.iglob("**/*", recursive=True))
86+
to_scan = [
87+
{"filename": path.name, "document": path.read_text(errors="replace")}
88+
for path in file_paths
89+
]
8890

8991
scan = client.multi_content_scan(to_scan)
9092
```

0 commit comments

Comments
 (0)