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

J

John [H2O]

I have a glob.glob search:

searchstring = os.path.join('path'+'EN*')
files = glob.glob(searchstring)
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?
 
S

Sean DiZazzo

I have a glob.glob search:

searchstring = os.path.join('path'+'EN*')

shouldn't that be os.path.join(path, '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(searchstring)
for f in files:
if not f[-1] =="*":
print f

Post a small *tested* example that recreates the error on your system.

~Sean
 
A

alex23

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top