How can I debug silent failure - print no output

Sayth Renshaw flebber.crue at gmail.com
Sat May 28 00:02:43 EDT 2016


On Saturday, 28 May 2016 13:06:59 UTC+10, Michael Torrie  wrote:

> Add more print() calls. Offhand I'd say that pq(filename=filename) is
> returning an empty list so that for loop is not doing anything.  Hence
> your debugging print() calls never happen.
> 
> Add sanity print()'s earlier in your program, and make sure everything
> you are iterating over is what you expect.

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.

[sayth at localhost pyXML]$ python3 racemeeting.py data/*.xml
set()
set()
set()


Sayth



More information about the Python-list mailing list