Python 模块*没有使用nosetest的属性*

Python 模块*没有使用nosetest的属性*,python,attributeerror,nose,Python,Attributeerror,Nose,我的任务来自《Python刻苦学习》一书。它是关于使用带有鼻子的测试的。 我在lexicon.py文件中有函数scan\u net: def scan_net(sentence): direction = ['north', 'south', 'east', 'west'] verb = ['go', 'kill', 'eat', 'breath'] stop_words = ['the', 'in', 'off'] nouns = ['bear', 'princ

我的任务来自《Python刻苦学习》一书。它是关于使用带有
鼻子的测试的。
我在
lexicon.py
文件中有函数
scan\u net

def scan_net(sentence):
    direction = ['north', 'south', 'east', 'west']
    verb = ['go', 'kill', 'eat', 'breath']
    stop_words = ['the', 'in', 'off']
    nouns = ['bear', 'princess', 'frog']

    words = sentence.split()
    result = []
    for i in range(len(words)):
        if words[i] in direction:
            result.append(('direction', words[i]))
        elif words[i] in verb:
            result.append(('verb', words[i]))
        elif words[i] in stop_words:
            result.append(('stop_words', words[i]))
        elif words[i] in nouns:
            result.append(('nouns', words[i]))
        #check for number and if it is go out of the loop using continue
        try:
            if(int(words[i])):
                result.append(('number', words[i]))
                continue
        except ValueError:
            pass
        else:
            result.append(('error', words[i]))
    return result
这是我的测试文件:

from nose.tools import *
import lexicon

def test_directions():
    result = lexicon.scan_net("north south east")
    assert_equal(result, [('direction', 'north'),
                        ('direction', 'south'),
                        ('direction', 'east')])
运行
nosetests\lexicon\u tests.py
命令后
属性错误:模块“lexicon”没有属性“scan\u net”


我的进口有什么问题?为什么它看不到函数
scan\u net

您的路径中可能有一个名为
lexicon
的文件夹,这是首选文件夹,应该重命名其中一个文件夹,以便更清楚应该导入哪个文件夹

您仍然可以从lexicon import scan\u net导入
,但通常使用不同的名称会使您的生活更轻松


请参见

在同一路径中是否还有名为“lexicon”的文件夹?有趣的是,你可能会发现和(一起)比鼻子更干净、更友好,也就是说,非常感谢。你是对的,这回答了你的问题吗?