I would like to do something like this:
find -name "foo*" | python main.py
and access all the files that were found by the find program. How do I access that in Python?
To access command-line arguments from within a Python program, first import the sys package. You can then refer to the full set of command-line arguments, including the function name itself, by referring to a list named argv. In either case, argv refers to a list of command-line arguments, all stored as strings.
Python sys module stores the command line arguments into a list, we can access it using sys. argv . This is very useful and simple way to read command line arguments as String. Let's look at a simple example to read and print command line arguments using python sys module.
argv is a list in Python that contains all the command-line arguments passed to the script. It is essential in Python while working with Command Line arguments.
import sys
for line in sys.stdin:
print line
Use sys.stdin.read() or raw_input()
A pipeline just changes the stdin file descriptor to point to the pipeline that the command on the left is writing to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With