why should it wait?
▶ ./python -m ast
Namespace(infile=<_io.BufferedReader name='<stdin>'>, mode='exec', no_type_comments=True, include_attributes=False, indent=3)
<_io.BufferedReader name='<stdin>'>
it’s stuck here, I guess we can wait for user input and can signal(signal of pressing enter key) the script to continue but should we make it stuck? is this an intended behavior?
jeanas
(Jean Abou Samra)
July 7, 2023, 8:14pm
2
What’s the problem here? Reading stdin when called without argument is pretty common for shell utilities in general.
like they keep on waiting for input?, how do they know that the user has entered the input, and I need to process the input now?
jeanas
(Jean Abou Samra)
July 7, 2023, 8:17pm
4
Whenever something (Python, cat
, grep
, whatever) is waiting on stdin, you can press Control-D to terminate the input.
but they didn’t hang right they generate --help message
▶ grep
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
jeanas
(Jean Abou Samra)
July 7, 2023, 8:20pm
6
Try grep a
(grep
is called as grep pattern file
, grep pattern file1 file2 ...
or grep pattern
, the latter reads input to search on stdin).
Or just cat
.
got you, I should have posted this to help, I was not aware of the intended use-case of running ast
as a script, and tools like these work like this only.
jeanas
(Jean Abou Samra)
July 7, 2023, 8:23pm
8
(I’ve moved the topic to Python Help .)
1 Like
Hi, can you move back to the idea I want to hear others views as well?
▶ grep "fike"
sadk
asd
sad
sads
fike
**fike**
as
dsa
dasd
here they are constantly looking at the input and processing it ,same for cat
▶ cat
g
**g**
h
**h**
ast
should at least generate a --help message or process the stdin after enter is pressed
jeanas
(Jean Abou Samra)
July 7, 2023, 8:57pm
10
So you want python -m ast
to emit output on the fly while reading the input? That’s not possible: grep
for example can compute part of the output with only part of the input (just search for the pattern in that part of the input), but python -m ast
needs a full module to process. Just look at
$ python -m ast
2+2
3+3
Module(
body=[
Expr(
value=BinOp(
left=Constant(value=2),
op=Add(),
right=Constant(value=2))),
Expr(
value=BinOp(
left=Constant(value=3),
op=Add(),
right=Constant(value=3)))],
type_ignores=[])
which is not the concatenation of
$ python -m ast
2+2
Module(
body=[
Expr(
value=BinOp(
left=Constant(value=2),
op=Add(),
right=Constant(value=2)))],
type_ignores=[])
and
$ python -m ast
3+3
Module(
body=[
Expr(
value=BinOp(
left=Constant(value=3),
op=Add(),
right=Constant(value=3)))],
type_ignores=[])
Such cases are also common (sort
, gzip -f
, git apply
, pandoc --from markdown --to html
come to mind).
2 Likes
Thanks, I think I got it now.
1 Like