Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: cs@zip.com.au Newsgroups: comp.lang.python Subject: Re: How can I debug silent failure - print no output Date: Sun, 29 May 2016 08:43:13 +1000 Lines: 66 Message-ID: References: <962627be-d620-4ba1-9429-68ed3f792b42@googlegroups.com> <20160528224313.GA38853@cskk.homeip.net> Reply-To: python-list@python.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de XltPLlkAQ9+r8V8oPazqqAQ7iuucOx5E6LMz4qyCVTLg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'args': 0.04; 'python3': 0.05; '(b)': 0.07; 'filenames': 0.07; 'puts': 0.07; 'cc:addr :python-list': 0.09; 'subject:How': 0.09; 'command.': 0.09; 'namespace': 0.09; 'statements': 0.09; 'python': 0.10; 'pushed': 0.13; 'syntax': 0.13; 'do,': 0.15; 'argument': 0.15; 'properly': 0.15; '"*"': 0.16; '2016': 0.16; '>on': 0.16; '_after_': 0.16; 'argparse': 0.16; 'dummy': 0.16; 'empty.': 0.16; 'expands': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'invoking': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'perhaps:': 0.16; 'received:172.16.3': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'say.': 0.16; 'simpson': 0.16; 'subject:debug': 0.16; 'wrote:': 0.16; 'later': 0.16; 'shell': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'extension': 0.20; 'first,': 0.20; 'prevent': 0.20; '(a)': 0.22; 'arguments': 0.22; 'parser': 0.22; 'parsing': 0.22; 'cheers,': 0.22; 'cc:no real name:2**0': 0.22; '(where': 0.23; 'passing': 0.23; 'this:': 0.23; 'second': 0.24; 'unix': 0.24; 'xml': 0.24; 'header:In-Reply-To:1': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; 'command': 0.26; 'expansion': 0.27; "skip:' 10": 0.28; 'quoting': 0.29; 'print': 0.30; 'skip:[ 10': 0.31; 'run': 0.33; 'options': 0.33; 'useful': 0.33; 'common': 0.33; 'usually': 0.33; 'foo': 0.33; 'lets': 0.33; 'option.': 0.33; 'safely': 0.33; 'traditional': 0.33; 'file': 0.34; 'running': 0.34; 'gets': 0.35; 'dir': 0.35; 'filter': 0.35; 'path': 0.35; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'skip:p 20': 0.38; 'files': 0.38; 'end': 0.39; 'means': 0.39; 'data': 0.39; 'whatever': 0.39; 'from:no real name:2**0': 0.60; 'your': 0.60; 'reach': 0.61; 'here.': 0.62; 'saturday,': 0.63; 'cameron': 0.66; 'said:': 0.66; 'header:Reply-To:1': 0.67; 'reply- to:no real name:2**0': 0.71; 'received:61': 0.72; 'special': 0.73; 'correctly?': 0.84; 'intending': 0.84; 'obvious.': 0.84; 'reply- to:addr:python.org': 0.84 X-Authentication-Info: Submitted using ID cskk@bigpond.com X-Authority-Analysis: v=2.0 cv=WO39rwQR c=1 sm=1 a=LH/sS1xOHRo68k81xwb3Ig==:17 a=yrkiwgmsf1kA:10 a=pGLkceISAAAA:8 a=vrnE16BAAAAA:8 a=CuxuXxlw73SWJTuT9sQA:9 a=CjuIK1q_8ugA:10 a=LH/sS1xOHRo68k81xwb3Ig==:117 Content-Disposition: inline In-Reply-To: <962627be-d620-4ba1-9429-68ed3f792b42@googlegroups.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20160528224313.GA38853@cskk.homeip.net> X-Mailman-Original-References: <962627be-d620-4ba1-9429-68ed3f792b42@googlegroups.com> Xref: csiph.com comp.lang.python:109222 On 28May2016 03:32, Sayth Renshaw wrote: >On Saturday, 28 May 2016 19:44:53 UTC+10, Sayth Renshaw wrote: >> On Saturday, 28 May 2016 18:02:06 UTC+10, Sayth Renshaw wrote: >> > So how do i get argparse to read the file arguments correctly? >> > >> > Looking at the namespace it all gets pushed into path and extension remains empty. >> > >> > [sayth@localhost pyXML]$ python3 racemeeting.py data/ *.xml >> > Namespace(extension='', path=['data/', '*.xml']) >> > This is the section I am running >> > >> > parser = argparse.ArgumentParser() >> > parser.add_argument("path", nargs="+") >> > parser.add_argument('-e', '--extension', default='', >> > help='File extension to filter by.') >> > >> > args = parser.parse_args() >> > name_pattern = "*" + args.extension >> > print(args) >> >> Ah if only i used argparse properly >> >> python racemeeting.py data/ -e *.xml There are a couple of things here. First is that a normal UNIX command puts all the options first, so you should be desiging your command line to run like this: python racemeeting.py -e *.xml data or perhaps: python racemeeting.py -d data -e *.xml It is traditional to stop parsing options such as -e when you reach the first non-option, because that lets one put whatever is necessary safely _after_ the options without fear that one of the arguments will resemble an option. For example, suppoing you have a file with the name "-e" and said: somecommand -f foo dir * intending to use all the local filenames after "dir". In your current scheme (accepting options after "dir") a "-e" appearing later would be misinterpreted. The second is to be aware that the shell expands globs _before_ invoking the command. This is extremely useful because it means that (a) commands usually don't need to do their own glob expansion and (b) all commands end up using the same glob syntax because it is common to the shell, not a command-specific special syntax. Which makes everything easier to use. The upshot of that is that you should _either_ be quoting "*.xml" on your command line to prevent expansion, _or_ you should not be bothering with he asterisk, instead passing the argument ".xml" or even just "xml". As an experiment, make two dummy XML files in your current directory (where your script is): >>dummy1.xml >>dummy2.xml and run your script passing *.xml as you currently do, and see what your print statements say. This should make the effect obvious. Cheers, Cameron Simpson