How can I debug silent failure - print no output

Sayth Renshaw flebber.crue at gmail.com
Sat May 28 02:35:21 EDT 2016


> >
> >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



More information about the Python-list mailing list