This text file is AssemblySecDetails.txt
Section: AS Part ID: ABS01 Order from warehouse to aircond section: 500 quantity left in the warehouse: 1000
Section: BS Part ID: BBS02 Order from warehouse to brake section: 600 quantity left in the warehouse: 1000
Section: ES Part ID: ES04 Order from warehouse to engine section: 100 quantity left in the warehouse: 1000
Section: BWS Part ID: BWBS03 Order from warehouse to bodywork section: 700 quantity left in the warehouse: 9
Section: TS Part ID: TS05 Order from warehouse to tyre section: 300 quantity left in the warehouse: 1000
Section: AS Part ID: ABS01 Order from warehouse to aircond section: 300 quantity left in the warehouse: 5
I am trying to find out which Part ID has the quantity of lesser than 10
fHand = open("AssemblySecDetails.txt", 'r')
partsDetails = fHand.readlines()
def condition(parts):
filteredLines = [parts for parts in partsDetails if condition(parts)]
quantity = re.search("quantity left in the warehouse: (d+)", parts).group(1)
quantity = int(quatity)
return quantity < 10
condition(parts)
output
UnboundLocalError: local variable 'parts' referenced before assignment
What is the mistake in my code and how should I call the function?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…