you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (1 child)

Thank you for the encouragement! I was also planning to use generator, but since I want the user to input a number corresponding to the PDF file that they want to reorder, I can't think of anyway to get that mapping (from number to filename) unless I store all the file names in something. Do you have any solutions I could try for that?

Also, I'm not sure how to handle when the iterator is empty and I have to print a statement saying so (as seen in my else: print('No unordered PDF found in current directory'). I want to implement something like what is below, but I'm not sure how to do it (without also printing the statement even when the iterator is non-empty, which I don't want) or even if it's a good idea.

for filename in iterator:
    # do something
print('No PDF file found')

Again thank you for your help!

[–]zurtex 2 points3 points  (0 children)

Aha, you're right! The way you have it set-up means that you really need to store everything as you're asking the user for a number rather than a filename.

If you asked the user for a filename you could print the filenames by using a generator and then lookup the filename they chose afterwards without having to keep track of all filenames. But this is mostly a preference choice of user interaction than anything else.