xyzman xyzman - 3 months ago 11
Python Question

How to always select the last file in a list?

Long story short, I am using Python to plot many files on the same grid. I won't post the whole program, as it would be unhelpful and unnecessarily long. This is what I need help with

To summarize, how to I get

ifl == 1
to say something that in pythonic language would equal
ifl == last file in directory
? Thanks

Answer

What about:

if ifl == len(file_location):
    ....

Also, you don't actually need the index, you can do this:

file_location = glob.glob('../Data/2016/July/*.nc')

for fl in file_location:
    ...
    if fl == file_location[-1]:
        Plot_Map(temp,lon,lat)
    ...