bibjsy 发表于 2022-9-26 07:58:00

搞不明白了 求大神讲解下

前面创建的2个函数没有问题正常运行 第3个函数报错

Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\课件\最后1116668886611.py", line 18, in <module>
    censored_text_creata('Try','lame!lame!lame!')
File "C:\Users\Administrator\Desktop\课件\最后1116668886611.py", line 17, in censored_text_creata
    text_creata(name,clean_msg)
NameError: name 'text_creata' is not defined. Did you mean: 'text_create'?

代码如下:

def text_create(name,msg):                              
    desktop_path = 'C:\\Users\\Administrator\\Desktop\\'
    full_path = desktop_path + name + '.txt'
    file = open(full_path,'w')
    file.write(msg)
    file.close()
text_create('hello','hello word')


def text_filter(word,censored_word = 'lame',changed_word = 'Awesome'):
    return word.replace(censored_word,changed_word)
text_filter('Python is lame')


def censored_text_creata(name,msg):
    clean_msg = text_filter(msg)
    text_creata(name,clean_msg)
censored_text_creata('Try','lame!lame!lame!')

bibjsy 发表于 2022-9-26 08:26:22

卧槽 找到原因了

Twilight6 发表于 2022-9-26 09:53:45



方法名打错了吧, 最后一个 e 打错成了 a,即 text_creata 改成 text_create

bibjsy 发表于 2022-9-26 15:47:53

是的   开始没有注意到
页: [1]
查看完整版本: 搞不明白了 求大神讲解下