Member Avatar for leegeorg07

hello, i just started a paper round and ive started doing what i do best : obsessing about it and i want to know if there is any way that i can open and close images of the different newspapers to learn them? i would prefer to do this with modules already in the folders but if i need something else then i guess i will have to do it.

Can you please elaborate a little bit more on what you're trying to do, exactly? We might be able to help if you clarify your question...

Member Avatar for leegeorg07

sorry, what i want to do is something like this

import webbrowser, random
import os
import os.path #or whatever modules i need
dir_name = r"where my pictures of newspaper logos are"
def file_lister(currdir, mylist=[]):
    """
    returns a list of all files in a directory and any of
    its subdirectories
    note that default mylist becomes static
    """
    for file in os.listdir(currdir):
        # add directory to filename
        full_name = os.path.join(currdir, file)  
        if not os.path.isdir(full_name):
            mylist.append(full_name)
        else:
            # recurse into subdirs
            file_lister(full_name)
    return mylist


file_lists = file_lister(dir_name)
file_list = filter(lambda x: x.lower().endswith(".jpg"),file_lister(dir_name))# i will save them all as .jpg extension

while 1:
    img = random.choice(file_list)
    webbrowser.open(os.path.join(dir_name,img))
    time.sleep(5)
    webbrowser.close(os.path.join(dir_name,img)) #this is what i dont know, there isnt a webbrowser.close function

so that it will flash up an image for a short time (5 secs) and then close it, it will then ask me what it is, if it is correct then it will go to the next. but i dont know how to do that bit and if my above code is the best to do that, even though it doesnt do everything i want at the moment

I was also thinking, would it be better to have a dictionary of files and names to use instead?

Personally i think in the end that it would be easier if you used a GUI, that way you could control everything so much easier. If you are interested in a GUI it will mean added control as well as less difficulty with some things such as making sure that the webbrowser loads fast enough to let you look at the image for 5 seconds

Member Avatar for leegeorg07

thanks, how could i do that?

Member Avatar for leegeorg07

thanks im taking a look now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.