jupyter中用find方法查找文件中字符串

我这是想判断是否有指定名字的文件,结果他一直说

name 'find' is not defined

没定义,请问这里有什么问题吗

 

find方法查找指定子字符串的首次出现,前面要加上字符串。直接用find(...)会报没有定义错误。用in方法查找和判断更容易些。denglu()函数可以这样改:

def denglu():
    username=input('your id:')
    passwd=input('password:')
    with open('id.txt','r') as fi,open('pass.txt','r') as fp:
        userid=[x.strip() for x in fi.readlines()]
        key={x.split(',')[0]:x.split(',')[1].strip() for x in fp.readlines()}
    if username in userid and key[username]==passwd:
        print('welcome login!')
    else:
        print('please check your id or password')

denglu()

#id.txt:
123
456
#pass.txt:
123,abc
456,def

 

 

报错是什么?你的findu函数是怎么实现的,要贴出来