使用输入通过 Dictreader 过滤解析的 csv

Using input to filter parsed csv through Dictreader

我是 python 的新手,我的 objective 是创建一个能够通过用户输入过滤 csv 数据库的基本脚本。 我搜索了各种帖子和答案,并提出了这段代码,但由于某种原因没有给出所需的响应,有人可以告诉我它是正确的还是错误的方法?非常感谢您的帮助,下面是代码:

import csv

from encodings import utf_8
from csv import DictReader
from multiprocessing import Value
from typing import Dict
with open('Book.csv', newline='', ) as file :
    reader= DictReader(file)
  
    for row in reader :
     print(row)
    
  

    ask_age=(input("enterage:"))
    
    for row in reader :
     for key,val in row.items : 
        if ask_age==str in row.items['Age',str] is True : 
         print(row.items['Name',str])

这是一个数据库示例(这是一个模拟数据库,因为我还在研究脚本)

Age,Name,Sex
10,brian,male
30,amilia,female
40,raylie,female 

提示:

Enter age: 10

输出:

brian is 10

脚本:

import csv

ask_age = (input("Enter age:"))

with open('Book.csv', 'r') as file :
    reader = csv.reader(file)
  
    for row in reader :
        if row[0] == ask_age:
            print(row[1] + ' is ' + ask_age) 

CSV 格式:

|----|--------|--------|
| 10 | brian  | male   |
| 30 | amilia | female |
| 40 | raylie | female |