[Tutor] Executing shell commands

Mats Wichmann mats at wichmann.us
Sun Feb 16 08:54:23 EST 2020


On 2/16/20 12:54 AM, Phil wrote:
> On 16/2/20 3:04 pm, Mats Wichmann wrote:
>> you dont need to run an external command to collect the files, look at
>> the glob module and even more apropos the pathlib module. 
> 
> It turned out to be easier that I had expected and this is what I came
> up with:
> 
> from pathlib2 import Path
> from glob import glob
> 
> path = Path("/home/phil/Downloads/")
> 
> for x in path.glob("*.gpx"):
>     print (x)

just note: you don't need the glob import line here, you're asking for
(and getting because you use the qualified name path.glob) the glob
method of the Path object from pathlib.





More information about the Tutor mailing list