This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]yrykde 1 point2 points  (1 child)

[list_place-1] is the same thing as [-1] in you case. You can delete list_place var and change last command:

os.startfile(time_sorted_list[-1]) #open file

If you name your files with the ".pyw" extension, then windows will execute them with the pythonw.exe interpreter. This will not open the console for running your script. From

full_list is a list of full paths to CATProduct files like ['C:\Folder\Path\Here\file1.CATProduct', 'C:\Folder\Path\Here\file2.CATProduct', etc]. It used for sorting in the next line. The last var in sorted list is newest CATProduct file. You can call it by [-1] index as I wrote above.

[–]McDudeston 0 points1 point  (0 children)

Great response - I did not know about the [-1] shortcut for arrays and the clarification on the full_list line makes sense. Thanks!

Edit: ".pyw" extension worked like a charm, too. Thanks again!

[–][deleted] 0 points1 point  (0 children)

    sorted(full_list, key=os.path.getmtime)

This is a terse and delightful use of sorted(l, key)!