I’m trying to make this alias in the debugger and define it like this:
(Pdb) alias dir import glob myfiles = glob.glob(%1) for i in myfiles: print(i)
(Pdb) dir *.py
*** SyntaxError: invalid syntax
(Pdb)
As you can see when I use the alias I get a Syntax Error. For this example I would like to get a directory of files in the program dir based on the filespec I type in.
I did some searching and have come up empty. I can do a loop, but since Python does not seem to have a line separator like Perl does (Perl uses semi-colon at the end of lines) I’m stumped. It does seem like Python uses CRLF as a command separator.
EDIT: I have not tried putting the aliases in the .pdbrc file yet.
The following worked for me (note that %1 needs to be quoted):
alias dir import glob; print(glob.glob("%1"))
Alternatives:
alias dir1 import glob; _ = [print('-', x) for x in sorted(glob.glob("%1"))]
alias dir2 import glob; lis=glob.glob("%1"); print(lis)
You can also first import glob and then define an alias that uses glob. So, the semi-colon is usable to separate Python statements, just like in regular Python code.
In particular in Hans’ example, note the semicolon separating each
Python statement. Your (Chuck’s) attempt had no semicolon so Python was
treating it as one statement.