-6

I'm trying to get a list of files on python using glob, however it is returning zero.

the method goes:

def read(self,folders)

"folders" input contain the files needed to be looped through

I used

files = glob(folders)
AR16
  • 5
  • 4
  • 2
    `glob` only finds the file name. Files are opened with `open` – DeepSpace Apr 25 '18 at 08:13
  • 3
    Use `code formatting`. Don't post pictures of your code. https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557 – FHTMitchell Apr 25 '18 at 08:14
  • 2
    Isn't posting code as text a thousand times easier than cropping and uploading pictures of it? – Aran-Fey Apr 25 '18 at 08:15
  • 1
    Possible duplicate of [Reading entire file in Python](https://stackoverflow.com/questions/7409780/reading-entire-file-in-python) – FHTMitchell Apr 25 '18 at 08:15

1 Answers1

0

One way you can do it, which yield the contents of each file in turn.

from glob import glob

class C:
    def read(self, folders):
        for file in glob(folders):
            with open(file) as f:
                yield f.read()
FHTMitchell
  • 11,793
  • 2
  • 35
  • 47