Exercise: Find Text Files With Glob
Bartosz Zaczyński RP Team on June 20, 2026
@bart.jutte, the empty list ([]) is actually the useful clue. Path(directory).glob("*") doesn’t raise when the directory doesn’t exist, it just yields nothing, so an empty list even with a plain * almost always means glob is searching a different folder than you expect rather than a pattern issue.
The usual cause is a relative path resolving against the wrong working directory. IDLE and PyCharm often start with a current directory that isn’t where your files are, so something like "texts" ends up pointing at an empty (or missing) location. Quick check:
from pathlib import Path
directory = Path("your/path")
print(directory.resolve(), directory.exists())
print(list(directory.iterdir()))
If .exists() is False or .iterdir() is empty, point directory at the absolute path where the .txt files actually live (for example Path.home() / "some_folder").
A couple of side notes: .glob("*.txt") only looks one level deep, so for files in subfolders use .rglob("*.txt"). And the exercise platform passes in a directory that already contains test files, which is why your solution validates there even when a local run finds nothing.
The PyCharm “didn’t run at all” part sounds like a local environment or antivirus thing rather than your code. Running from a terminal with python your_script.py (or staying in IDLE) should unblock you, and if you can paste the exact error, the rest of the team and I are happy to take a look.
Ziggy on Oct. 24, 2026
I don’t get a generator but a map class, is there some error here? I don’t understand this answer. What is a generator is this explained somewhere in the Python Basics course? What did I mis?
My result is <class ‘map’>
from pathlib import Path
print(type(Path.home().glob("*")))
<class 'map'>
Bartosz Zaczyński RP Team on Oct. 30, 2026
@Ziggy you didn’t miss anything 🙂 What you see depends on your Python version. Up to Python 3.12, .glob() returns a generator. Starting with Python 3.13, it returns a map object instead. The solution notes were written with the older behavior in mind.
For this exercise, the difference doesn’t matter. Generators and map objects are both iterators, so you can loop over them or pass them to functions like list() and sorted():
from pathlib import Path
for path in Path.home().glob("*"):
print(path.name)
That’s also how the course describes it. In Searching for Files Using Glob Methods, the result of .glob() is called an iterator that you can pass to list(). In Iterating Over Directory Contents, you can see a generator object show up when calling .iterdir().
If you want to learn more about generators, the generator entry in the Python reference gives a short overview, and How to Use Generators and yield in Python goes into more detail.
I’ll pass this along to the rest of the team so we can update the solution notes.
Become a Member to join the conversation.
bart.jutte on June 13, 2026
Usually, I run the code of exercises on my local machine to see if they work. This one, I wasn’t able to get working for some reason. I normally use PyCharm for this, but that didn’t run at all (some security thing?). IDLE resulted in empty
[]results, even after modifying the answer to include subfolders or just any file. Puzzling.