I use the input function from the fileinput module to accept a script through pipes or input file Here is a minimal script:
finput.py
import fileinput with fileinput.input() as f: for line in f: print(line)
After executing this script executable, I run ls | ./finput.py ls | ./finput.py and getting unexpected error message
./finput.py: line 1: import: command not found ./finput.py: line 3: syntax error near unexpected token `(' ./finput.py: line 3: `with fileinput.input() as f:'
The only fix I found is when I add #!/usr/bin/env/python3 before the import statement.
But this problem seems to be related only to the fileinput module. Since the script worked without shebang :
fruit.py
import random fruits = ["mango", "ananas", "apple"] print(random.choice(fruits))
Now what am I missing? Why can't the import command be found since shebang not required in finput.py ?
python shebang
styvane
source share