Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: Why are my files in in my list - os module used with sys argv Date: Tue, 19 Apr 2016 02:17:15 +0100 Lines: 73 Message-ID: References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> <5715871B.5000003@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de wo+0kRg/yJY6HvhQL+6p/wIN73iUoKJoBSdSR4kayeyA== 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; 'skip:[ 20': 0.03; 'sys': 0.05; 'bash': 0.07; 'mask': 0.07; 'res': 0.09; 'subject:Why': 0.09; 'subject:files': 0.09; 'subject:module': 0.09; 'python': 0.10; 'attrs': 0.16; 'expands': 0.16; 'files)': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'script?': 0.16; 'statement.': 0.16; 'sys.exit(1)': 0.16; 'wrote:': 0.16; 'linux,': 0.18; 'filtering': 0.22; 'skip:( 40': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'subject:list': 0.26; 'command': 0.26; 'linux': 0.26; 'followed': 0.27; 'nominations': 0.29; 'skip:( 50': 0.29; 'print': 0.30; 'skip:[ 10': 0.31; 'getting': 0.33; 'problem': 0.33; 'doubt': 0.33; 'case,': 0.34; 'structure': 0.34; 'file': 0.34; 'running': 0.34; 'dir': 0.35; 'asking': 0.35; "isn't": 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'doing': 0.38; 'names': 0.38; 'files': 0.38; 'end': 0.39; 'why': 0.39; 'data': 0.39; 'received:192': 0.39; 'skip:x 10': 0.40; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'ever': 0.60; "you'll": 0.61; 'believe': 0.66; 'prompt': 0.79 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=K//fZHiI c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=g6eZhxcjQ0YmoVGN8oQA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 In-Reply-To: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 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: <5715871B.5000003@mrabarnett.plus.com> X-Mailman-Original-References: <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> Xref: csiph.com comp.lang.python:107285 On 2016-04-19 00:44, Sayth Renshaw wrote: > Hi > > Why would it be that my files are not being found in this script? > > from pyquery import PyQuery as pq > import pandas as pd > import os > import sys > > if len(sys.argv) == 2: > print("no params") > sys.exit(1) > > dir = sys.argv[1] > mask = sys.argv[2] > > files = os.listdir(dir) > > fileResult = filter(lambda x: x.endswith(mask), files) > > # d = pq(filename='20160319RHIL0_edit.xml') > data = [] > > for file in fileResult: > print(file) > > for items in fileResult: > d = pq(filename=items) > res = d('nomination') > attrs = ('id', 'horse') > data = [[res.eq(i).attr(x) for x in attrs] for i in range(len(res))] > > # from nominations > # res = d('nomination') > # nomID = [res.eq(i).attr('id') for i in range(len(res))] > # horseName = [res.eq(i).attr('horse') for i in range(len(res))] > > # attrs = ('id', 'horse') > > frames = pd.DataFrame(data) > print(frames) > > > I am running this from the bash prompt as > > (pyquery)sayth@sayth-E6410:~/Projects/pyquery$ python jqxml.py samples *.xml > > my directory structure > > (pyquery)sayth@sayth-E6410:~/Projects/pyquery$ ls -a > . .. environment.yml .git .gitignore #jqxml.py# jqxml.py samples > > and samples contains > > (pyquery)sayth@sayth-E6410:~/Projects/pyquery/samples$ ls -a > . 20160319RHIL0_edit.xml 20160409RAND0.xml > .. 20160402RAND0.xml 20160416RAND0.xml > > yet I get no files out of the print statement. > > Ideas? > I don't use Linux, but I think it might be a problem with what you have on the command line. I believe that Linux expands wildcarded names, so what you might be getting is "samples" followed by all the names in the current directory that match "*.xml". Even if that isn't the case, and mask is "*.xml", the filtering that you're doing is asking for those names that end with "*.xml"; you might find a name that ends with ".xml", but I doubt you'll ever find one that ends with "*.xml"!