Last active
March 3, 2023 00:42
-
-
Save bsnux/3805696ae4a637fae52981cd6e295b5d to your computer and use it in GitHub Desktop.
Useful Python one-liners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reading file lines from stdin | |
cat /tmp/test.txt | python -c 'import fileinput; [print(line, end="" for line in fileinput.input()] | |
python -c 'import fileinput; [print(line, end="") for line in fileinput.input()]' < /tmp/test.txt | |
# Printing the 3 lines of the file | |
python -c "import sys; sys.stdout.write(''.join(sys.stdin.readlines()[:3]))" < /tmp/test.txt | |
# Checking if file exists | |
python -c 'from pathlib import Path; print("yes") if Path("/tmp/metrics.txt").is_file() else print("no")' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment