Created
April 5, 2021 21:11
-
-
Save efontan/63a32ce84081e5255f95132633f25105 to your computer and use it in GitHub Desktop.
Search in CSV with Python
This file contains hidden or 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
#!/usr/bin/python | |
import csv | |
# input text you want to search | |
text = input("Input to search: ") | |
with open("/path/to/my/file.csv", "r") as f: | |
csv_file = csv.reader(f, delimiter=",") | |
# iterate over the csv list | |
for row in csv_file: | |
if text == row[0]: | |
print(f'Row found in file: {row}') | |
quit() | |
print("Text not found.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment