In [1]:
from ahh import ext, pre

In [2]:
glob_str = pre.join_cwd('data/*1948.nc') # create a wildcard string
glob_str


Out[2]:
'/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/*1948.nc'

In [3]:
ext.glob(glob_str) # basic usage


Out[3]:
['/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/air.sig995.1948.nc',
 '/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/rhum.sig995.1948.nc']

In [4]:
ext.glob(glob_str, 2) # validate expected length


Out[4]:
['/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/air.sig995.1948.nc',
 '/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/rhum.sig995.1948.nc']

In [5]:
ext.glob(glob_str, 4) # warns you if doesn't match


Expected 4 files from /mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/*1948.nc, but got 2 files!
Out[5]:
['/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/air.sig995.1948.nc',
 '/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/rhum.sig995.1948.nc']

In [6]:
ext.glob(glob_str, 4, mismatch='raise') # can also raise an error with mismatches


---------------------------------------------------------------------------
MismatchGlob                              Traceback (most recent call last)
<ipython-input-6-9226c1be1eff> in <module>()
----> 1 ext.glob(glob_str, 4, mismatch='raise') # can also raise an error with mismatches

/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/ext.py in glob(glob_str, nfiles, mismatch)
    779                 raise MismatchGlob(mismatch_fmt.format(nfiles,
    780                                                        glob_str,
--> 781                                                        glob_len)
    782                                    )
    783             else:

MismatchGlob: Expected 4 files from /mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/*1948.nc, but got 2 files!

In [7]:
glob_str = pre.join_cwd('data/*1947.nc') # create a wildcard string with typo
ext.glob(glob_str, 4) # raises error if the glob length is 0


---------------------------------------------------------------------------
EmptyGlob                                 Traceback (most recent call last)
<ipython-input-7-257751265190> in <module>()
      1 glob_str = pre.join_cwd('data/*1947.nc') # create a wildcard string with typo
----> 2 ext.glob(glob_str, 4) # raises error if the glob length is 0

/mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/ext.py in glob(glob_str, nfiles, mismatch)
    770     glob_len = len(glob_list)
    771     if glob_len == 0:
--> 772         raise EmptyGlob('No files match {0}!'.format(glob_str))
    773 
    774     mismatch_fmt = 'Expected {0} files from {1}, but got {2} files!'

EmptyGlob: No files match /mnt/c/Users/Solactus/Google Drive/Bash/ahh/ahh/data/*1947.nc!

In [ ]:


In [ ]: