Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107285

Re: Why are my files in in my list - os module used with sys argv

From MRAB <python@mrabarnett.plus.com>
Newsgroups comp.lang.python
Subject Re: Why are my files in in my list - os module used with sys argv
Date 2016-04-19 02:17 +0100
Message-ID <mailman.159.1461028646.6324.python-list@python.org> (permalink)
References <0bce26b1-ad3d-42c4-8f99-08e82d1bce88@googlegroups.com> <5715871B.5000003@mrabarnett.plus.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Why are my files in in my list - os module used with sys argv Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-18 16:44 -0700
  Re: Why are my files in in my list - os module used with sys argv Steven D'Aprano <steve@pearwood.info> - 2016-04-19 10:19 +1000
    Re: Why are my files in in my list - os module used with sys argv Peter Otten <__peter__@web.de> - 2016-04-19 10:16 +0200
      Re: Why are my files in in my list - os module used with sys argv Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-19 06:21 -0700
        Re: Why are my files in in my list - os module used with sys argv Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-19 06:31 -0700
        Re: Why are my files in in my list - os module used with sys argv Peter Otten <__peter__@web.de> - 2016-04-19 15:45 +0200
          Re: Why are my files in in my list - os module used with sys argv Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-19 07:18 -0700
  Re: Why are my files in in my list - os module used with sys argv MRAB <python@mrabarnett.plus.com> - 2016-04-19 02:17 +0100

csiph-web