This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: glob : some 'unix style' glob items are not supported
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Isaac Muse, Je GeVa, serhiy.storchaka, xtreak
Priority: normal Keywords:

Created on 2020-03-04 22:27 by Je GeVa, last changed 2022-04-11 14:59 by admin.

Messages (4)
msg363396 - (view) Author: Je GeVa (Je GeVa) Date: 2020-03-04 22:27
some common Unix style pathname pattern expansions are not supported :

~/ for $HOME
~user/ for $HOME of user
{1,abc,999} for enumeration

ex:

lets say
$ls ~
hello1.a hello2.a helli3.c

then :
$echo ~/hell*{1,3}.*
hello1.a helli3.c

while
>> glob.glob("~/hel*")
[]
>> glob.glob("/home/jegeva/hel*")
['hello1.a','hello2.a','helli3.c
>> glob.glob("/home/jegeva/hell*{1,3}.*")
[]
msg363416 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-03-05 03:58
This seems to be similar to issue9584. Below are the results in my zsh and bash in Mac.

bash

bash-3.2$ cd /tmp/
bash-3.2$ ls *py
hello_1.py	hello_2.py	hello_3.py
bash-3.2$ ls hell*{1-2}.*
ls: hell*{1-2}.*: No such file or directory
bash-3.2$ ls hell*[1-2].*
hello_1.py	hello_2.py

zsh

➜  /tmp ls *py
hello_1.py hello_2.py hello_3.py
➜  /tmp ls hell*{1-2}.*
zsh: no matches found: hell*{1-2}.*
➜  /tmp ls hell*[1-2].*
hello_1.py hello_2.py

Try using []

>>> import glob
>>> glob.glob("hell*[1-2].*")
['hello_2.py', 'hello_1.py']
msg363470 - (view) Author: Isaac Muse (Isaac Muse) Date: 2020-03-06 01:47
Brace expansion does not currently exist in Python's glob. You'd have to use a third party module to expand the braces and then run glob on each returned pattern, or use a third party module that implements a glob that does it for you.

Shameless plug:

Brace expansion: https://github.com/facelessuser/bracex

Glob that does it for you (when the feature is enabled): https://github.com/facelessuser/wcmatch

Now whether Python should integrate such behavior by default is another question.
msg363497 - (view) Author: Je GeVa (Je GeVa) Date: 2020-03-06 08:54
well ;

1) tilde expansion
this is an issue

2) brace expansion
have no clue how the engineers at the fruity company maimed your bash and
zsh man but brace expansion is core to both of them.
https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
http://zsh.sourceforge.net/Doc/Release/Expansion.html#Brace-Expansion

hence :

BASH
/tmp/testdir_issue39856$ $SHELL --version|head -n1
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
/tmp/testdir_issue39856$ ls
hello_1.py  hello_2.py  hello_3.py
/tmp/testdir_issue39856$ ls hell*{1,2}.*
hello_1.py  hello_2.py
/tmp/testdir_issue39856$ ls hell*{1..3}.*
hello_1.py  hello_2.py  hello_3.py

ZSH
nocte% $SHELL --version|head -n1
zsh 5.8 (x86_64-debian-linux-gnu)
nocte% ls hell*{1,2}.*
hello_1.py  hello_2.py
nocte% ls hell*{1..3}.*
hello_1.py  hello_2.py  hello_3.py

TCSH
nocte:/tmp/testdir_issue39856> /bin/tcsh --version
tcsh 6.21.00 (Astron) 2019-05-08 (x86_64-unknown-linux) options
wide,nls,dl,al,kan,sm,rh,nd,color,filec
nocte:/tmp/testdir_issue39856> ls hell*{1,2}.*
hello_1.py  hello_2.py

for history sake :
https://unix.stackexchange.com/questions/92819/why-is-brace-expansion-not-supported

Apparently :

"While brace expansion like {1,2} originates in csh in the late 70s, and
found its way to Bourne-like shells in bash/zsh/pdksh in the late 80s,
early 90s, the {n1..n2} variant came later first in zsh in 1995 (2.6-beta4).
bash copied it in 2004 (3.0) and ksh93 in 2005 (ksh93r)."
since glob claims the "unix style" and bash is the default unix shell, i
believe it should support it (or maybe change the tatile to 'unix from 40
years ago style' ),
i stand by the issue,

and Kart, on a side note i would sincerely update my base tools if i were
you, bash 3.2 is vulnerable to shellshock for exemple...

Le jeu. 5 mars 2020 à 04:58, Karthikeyan Singaravelan <
report@bugs.python.org> a écrit :

>
> Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:
>
> This seems to be similar to issue9584. Below are the results in my zsh and
> bash in Mac.
>
> bash
>
> bash-3.2$ cd /tmp/
> bash-3.2$ ls *py
> hello_1.py      hello_2.py      hello_3.py
> bash-3.2$ ls hell*{1-2}.*
> ls: hell*{1-2}.*: No such file or directory
> bash-3.2$ ls hell*[1-2].*
> hello_1.py      hello_2.py
>
> zsh
>
> ➜  /tmp ls *py
> hello_1.py hello_2.py hello_3.py
> ➜  /tmp ls hell*{1-2}.*
> zsh: no matches found: hell*{1-2}.*
> ➜  /tmp ls hell*[1-2].*
> hello_1.py hello_2.py
>
> Try using []
>
> >>> import glob
> >>> glob.glob("hell*[1-2].*")
> ['hello_2.py', 'hello_1.py']
>
> ----------
> nosy: +serhiy.storchaka, xtreak
> type:  -> behavior
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue39856>
> _______________________________________
>
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84037
2020-03-06 08:54:33Je GeVasetmessages: + msg363497
2020-03-06 01:47:18Isaac Musesetnosy: + Isaac Muse
messages: + msg363470
2020-03-05 03:58:45xtreaksetnosy: + xtreak, serhiy.storchaka
type: behavior
messages: + msg363416
2020-03-04 22:27:00Je GeVacreate