0

I am trying to code a program so I can search up a sheep earmarks and see what their lambs earmark is (and other information on the sheep). Sorry if this is explained badly - English is not my first language.

I have a code so I can import all the earmarks number from a txt file that I created. I don't know how to search for a specific earmark number.

I will be using this for personal use as it is much easier than having to sit there with the list on paper trying to find a number

import csv

results = []
with open('sau.txt', newline='') as inputfile:
for row in csv.reader(inputfile):
    results.append(row)
    print(row)

Here is my txt:

Sheep nr.7024: lamb nr.8001 og 8002   
Sheep nr.5072: lamb nr.8021, 8022, 8023, 8024  
Sheeo nr.3051: lamb nr.8095

The number on the ears

Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
  • Your text file is not formatted as a typical CSV. It may not work with this text file. I do not believe your with open statement will work either. You don't tell it "r" read the file. – Mike - SMT Apr 30 '18 at 21:08
  • Can you provide more context to your text file? What is the point of `:` here? Are you trying to search for the tag on the left of `:` and return the data to the right of the `:`? – Mike - SMT Apr 30 '18 at 21:12
  • Did you purposely select those three input lines to demonstrate that Sheep, might be misspelled/have typo and 'og' is sometimes used instead of comma? – visibleman May 01 '18 at 00:50
  • Basically, you need to split your 'row' string and compare the first value to the one you are looking for. Splitting strings and finding numbers is answered here,(among other places) https://stackoverflow.com/questions/4289331/python-extract-numbers-from-a-string – visibleman May 01 '18 at 00:56

0 Answers0