How can I debug silent failure - print no output

Sayth Renshaw flebber.crue at gmail.com
Sat May 28 03:14:39 EDT 2016


On Saturday, 28 May 2016 16:35:35 UTC+10, Sayth Renshaw  wrote:
> > >
> > >Ok after printing a few things i have found an error.
> > >
> > >def GetArgs():
> > >    '''parse XML from command line'''
> > >    parser = argparse.ArgumentParser()
> > >
> > >    parser.add_argument("path", nargs="+")
> > >    parser.add_argument('-e', '--extension', default='',
> > >                        help='File extension to filter by.')
> > >    args = parser.parse_args()
> > >
> > >    files = set()
> > >    name_pattern = "*" + args.extension
> > >    for path in args.path:
> > >        files.update(glob.glob(os.path.join(path, name_pattern)))
> > >
> > >    print(files)
> > >    return files
> > >
> > >a = GetArgs()
> > >print(a)
> > >
> > >so printing the files or the call to the function returns set() not the actual files.
> > 
> > Since you're constructing a set of filenames, this means it is probably 
> > returning the right kind of thing, but it is empty. That points to the glob not 
> > doing what you want or the for-loop not doing anything.
> > 
> > >[sayth at localhost pyXML]$ python3 racemeeting.py data/*.xml
> > >set()
> > >set()
> > >set()
> > 
> > So...  Add more prints!
> > 
> > Specificly, print(args) right after it is set, and put a print() _inside_ the 
> > loop before the call to files.update, probably printing "path", eg print("path 
> > =", path).
> > 
> > Then see what you learn.
> > 
> > Cheers,
> > Cameron Simpson 
> 
> Having done extra prints 
> 
> name_pattern = "*" + args.extension
>     for path in args.path:
>         print(args.path)
>         print(path)
>         files.update(glob.glob(os.path.join(path, name_pattern)))
> 
> it is getting the path and file however I think it is keeping the directory so i am not getting files.
> 
> [sayth at localhost pyXML]$ python3 racemeeting.py data/*.xml
> ['data/20160528RAND0.xml']
> data/20160528RAND0.xml
> set()
> set()
> ['data/20160528RAND0.xml']
> data/20160528RAND0.xml
> 
> Sayth
Actually think I have found the cause and its really small but on way its called.
I was calling
python3 racemeeting.py data/*.xml
which gives the directory and file as the path 
['data/20160528RAND0.xml']

But with arguments separated by a space I actually receive what i thought I would get a path and extension such as

sayth at localhost pyXML]$ python3 racemeeting.py data/ *.xml
Namespace(extension='', path=['data/', '*.xml'])
Traceback (most recent call last):
  File "racemeeting.py", line 35, in <module>

Sayth



More information about the Python-list mailing list