You could use the fileinput
module:
import fileinput
for line in fileinput.input():
pass
fileinput
will loop through all the lines in the input specified as file names given in command-line arguments, or the standard input if no arguments are provided.
Note: line
will contain a trailing newline; to remove it use line.rstrip()
Related Contents:
- How do I pass a string into subprocess.Popen (using the stdin argument)?
- How do I write to a Python subprocess’ stdin?
- Setting smaller buffer size for sys.stdin?
- How to open every file in a folder
- How do I read from stdin?
- Interactive input/output using Python
- Multiple inputs and outputs in python subprocess communicate
- How do I check if stdin has some data?
- Running an interactive command from within Python
- Python 3: How to specify stdin encoding
- Read from File, or STDIN
- Why does += behave unexpectedly on lists?
- Why does the expression 0 < 0 == 0 return False in Python?
- How can I use the apply() function for a single column?
- Pytesseract OCR multiple config options
- Why is Python 3.x’s super() magic?
- How to get different colored lines for different plots in a single figure?
- Using a dictionary to count the items in a list [duplicate]
- Pandas groupby multiple fields then diff
- Multiple ModelAdmins/views for same model in Django admin
- Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?
- Message: Element could not be scrolled into view while trying to click on an option within a dropdown menu through Selenium
- How to convert SQL Query result to PANDAS Data Structure?
- Is there a way to pass optional parameters to a function?
- How to generate a random number with a specific amount of digits?
- Pretty print 2D list?
- Using Colormaps to set color of line in matplotlib
- Ensure a single instance of an application in Linux
- RegEx with multiple groups?
- How to redirect stderr in Python?
- Python dictionary from an object’s fields
- How to run an .ipynb Jupyter Notebook from terminal?
- How to melt 2 columns at the same time?
- count the number of occurrences of a certain value in a dictionary in python?
- forward fill specific columns in pandas dataframe
- Element-wise string concatenation in numpy
- How to get Desktop location?
- Is there a built in package to parse html into dom?
- Why does numpy std() give a different result to matlab std()?
- Save and load model optimizer state
- How can I use a dictionary to do multiple search-and-replace operations? [duplicate]
- Simulating Key Press event using Python for Linux
- Convert column to row in Python Pandas
- Is there a “do … until” in Python? [duplicate]
- PyTorch: How to use DataLoaders for custom Datasets
- How do I create a multiline plot using seaborn?
- Fortran – Cython Workflow
- How to create a modal dialog in tkinter?
- Directly use Intel mkl library on Scipy sparse matrix to calculate A dot A.T with less memory
- import function from a file in the same folder