Skip to content

Instantly share code, notes, and snippets.

@efontan
Created April 5, 2021 21:11
Show Gist options
  • Save efontan/63a32ce84081e5255f95132633f25105 to your computer and use it in GitHub Desktop.
Save efontan/63a32ce84081e5255f95132633f25105 to your computer and use it in GitHub Desktop.
Search in CSV with Python
#!/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