samedi 25 août 2018

beginner python: my isfile() check stopped working

  1. This section was working and now it's NOT working. There's a possibility the working version didn't save, but this seems like a specific failure in code. I can't see where the problem might be. The print #debug works outside of the if isfile check but not inside. The Console output below isn't the whole directory, but the working loop does output the full list of files.

  2. Also, is it possible to put a print("string" + list) on the same line?

  3. And once I get the isfile() working I need to check the file contains an tag. Will I need to open/read file, then check text? Or is there some other way to scan a file?

Thank you!

def getChapterFiles(book):
    filepaths = getFilepaths(book)
    #print(filepaths) # debug #
    files = []
    chapters = []
    for book, filepaths, files in os.walk(book):
        for file in files:
            #print(os.path.join(book, file)) # debug #
            if os.path.isfile(file):
            ##and file.endswith(".html")
                chapters.append(os.path.join(book, file))           
                print(os.path.join(book, file)) # debug # 
    print("Chapters: ")
    print(chapters)        
    return chapters

CONSOLE outside isfile check:

D:\story_processing\test dirs\RR\Journey Into Darkness\Journey into Darkness -Chapter 6.html
Inside for loop, outside isfile: 
D:\story_processing\test dirs\RR\Journey Into Darkness\Journey Into Darkness -Chapter 7.html
Inside for loop, outside isfile: 
D:\story_processing\test dirs\RR\Journey Into Darkness\Journey into Darkness -Chapter 8.html
Chapters: 
[]

CONSOLE inside isfile check:

D:\story_processing\test dirs\RR\Journey Into Darkness\Journey Into Darkness -Chapter 4.html
Inside for loop, outside isfile: 
D:\story_processing\test dirs\RR\Journey Into Darkness\Journey into Darkness -Chapter 5.html
Inside for loop, outside isfile: 
D:\story_processing\test dirs\RR\Journey Into Darkness\Journey into Darkness -Chapter 6.html
Inside for loop, outside isfile: 
D:\story_processing\test dirs\RR\Journey Into Darkness\Journey Into Darkness -Chapter 7.html
Inside for loop, outside isfile: 
D:\story_processing\test dirs\RR\Journey Into Darkness\Journey into Darkness -Chapter 8.html
Chapters: 
[]

Image of corresponding directory:

Aucun commentaire:

Enregistrer un commentaire