Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: argument of type 'PosixPath' is not iterable

Tags:

python

glob

I am trying to recursively iterate through folders to assign a particular file to a variable for later parsing, however I am receiving the following error:

TypeError: argument of type 'PosixPath' is not iterable
Flask version 1.0.2 (not sure if its relevant)
Python version 3.7.3

Imports:

from pathlib import Path
from glob import glob

Code:

def parse_info(bundle_path):
    file_list = []
    for filename in Path(bundle_path).glob('**/*.*'):
        file_list.append(filename)

    for elem in file_list:
        if 'uname' in elem:
            print('present')

Call:

parse_info(<some path>)

The 'print(filename)' does print out all the files in that path and the desired search string is present in that print output, so I know it exists, however just not sure how to capture that element for later. Any help would be appreciated.

like image 528
vipercity Avatar asked Jul 14 '19 03:07

vipercity


1 Answers

The answer in this case was to cast the filename to a string when appending it to the list:

file_list.append(str(filename))
like image 95
vipercity Avatar answered Nov 11 '22 15:11

vipercity