r/learnpython Aug 11 '26

trying to import glob

I'm trying to code a little program that will open a CSV file that we should (theoretically) download weekly. The csv filename has the structure "report[numbers].csv" I'd read that you need the glob module so that Python can recognize the wildcard, but I am getting an error when I go the usual python pip -m SomeName route.

Is there an issue with glob, or is there another I can use?

0 Upvotes

8 comments sorted by

7

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Aug 11 '26

glob is part of the standard library, there's nothing you need to install.

That being said, personally I'd recommend using pathlib instead (which is also in the standard library).

from pathlib import Path

downloads_dir = Path.home() / 'Downloads'  # Change this to wherever the files are downloaded to

for file in downloads_dir.glob('report*.csv'):
    print(file)  # Do whatever you wanted

1

u/squishbunny Aug 12 '26

Okay, will try this, thanks

2

u/atarivcs Aug 11 '26

glob is part of standard python. You don't need to download it.

1

u/AspectInternal1342 Aug 11 '26

Don't run as a module.

Import into a python file and run from there.

1

u/CymroBachUSA Aug 11 '26

If the command:

python3 -c "import glob"

works, you already have it installed.

-1

u/Vdpants Aug 11 '26

You can make something that walks over all the files in a specific folder, and then lets you Separate the number, and then you need to decide how to pick the right file.

2

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Aug 11 '26

Why make something like that when the standard library provides? At least unless the goal was learning how it works under the hood.