appending * to glob returns files with '*' !!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John [H2O]

    appending * to glob returns files with '*' !!


    I have a glob.glob search:

    searchstring = os.path.join('p ath'+'EN*')
    files = glob.glob(searc hstring)
    for f in files:
    print f


    ___
    This returns some files:
    EN082333
    EN092334
    EN*

    My routine cannot handle the '*' and it should'nt be returned anyway? :-/

    A bug?



    --
    View this message in context: http://www.nabble.com/appending-*-to...p19579121.html
    Sent from the Python - python-list mailing list archive at Nabble.com.

  • Sean DiZazzo

    #2
    Re: appending * to glob returns files with '*' !!

    On Sep 19, 1:37 pm, "John [H2O]" <washa...@gmail .comwrote:
    I have a glob.glob search:
    >
    searchstring = os.path.join('p ath'+'EN*')
    shouldn't that be os.path.join(pa th, 'EN*') ?
    ___
    This returns some files:
    EN082333
    EN092334
    EN*
    Mine doesn't return that last string.
    >
    My routine cannot handle the '*' and it should'nt be returned anyway? :-/
    >
    Well, its an easy fix.

    files = glob.glob(searc hstring)
    for f in files:
    if not f[-1] =="*":
    print f
    A bug?
    Post a small *tested* example that recreates the error on your system.

    ~Sean

    Comment

    • alex23

      #3
      Re: appending * to glob returns files with '*' !!

      On Sep 20, 6:37 am, "John [H2O]" <washa...@gmail .comwrote:
      My routine cannot handle the '*' and it should'nt be returned anyway? :-/
      >
      A bug?
      Not at all. That's the same behaviour you'll get if you do 'ls EN*'.

      In your case, you're asking to match on anything that begins with EN,
      a subset of files that -includes- EN*.

      Why do you consider this behaviour surprising?

      Comment

      • Erik Max Francis

        #4
        Re: appending * to glob returns files with '*' !!

        John [H2O] wrote:
        I have a glob.glob search:
        >
        searchstring = os.path.join('p ath'+'EN*')
        files = glob.glob(searc hstring)
        for f in files:
        print f
        >
        >
        ___
        This returns some files:
        EN082333
        EN092334
        EN*
        >
        My routine cannot handle the '*' and it should'nt be returned anyway? :-/
        >
        A bug?
        No, it means you actually have a file named 'EN*' in the directory.

        --
        Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
        San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
        Many would be cowards if they had courage enough.
        -- Thomas Fuller

        Comment

        • John [H2O]

          #5
          Re: appending * to glob returns files with '*' !!


          No bug indeed, Erik was correct, in fact I had files with the * in the
          name...

          Thanks all for your replies!


          Erik Max Francis wrote:
          >
          John [H2O] wrote:
          >
          >I have a glob.glob search:
          >>
          >searchstring = os.path.join('p ath'+'EN*')
          >files = glob.glob(searc hstring)
          >for f in files:
          > print f
          >>
          >>
          >___
          >This returns some files:
          >EN082333
          >EN092334
          >EN*
          >>
          >My routine cannot handle the '*' and it should'nt be returned anyway? :-/
          >>
          >A bug?
          >
          No, it means you actually have a file named 'EN*' in the directory.
          >
          --
          Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
          San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
          Many would be cowards if they had courage enough.
          -- Thomas Fuller
          --

          >
          >
          --
          View this message in context: http://www.nabble.com/appending-*-to...p19638699.html
          Sent from the Python - python-list mailing list archive at Nabble.com.

          Comment

          Working...