モジュールをインポートして、そのモジュールの関数を現在のpythonファイルで使用しようとしています。 他のモジュールのpython関数の使い方
私はparser_tests.pyファイルにnosetestsを実行しますが、それは例えばそのは明らかにparsrer.pyファイルで定義されているparse_subject機能が見つからない「定義されていない名 『parse_subject』」で失敗し
これはparsrerファイルである: WORD_LIST場合: ワード= word_list.pop(0)
DEF(WORD_LIST、期待)と一致def peek(word_list):
if word_list:
word = word_list[0]
return word[0]
else:
return None
#Confirms that the expected word is the right type,
DEF 0
if word[0] == expecting:
return word
else:
return None
else:
return None
(WORD_LIST、word_type)スキップ: 一致(WORD_LIST、word_type)
DEF parse_verb(WORD_LIST): (WORD_LIST、 '停止')スキップPEEK(WORD_LIST)== word_typeながら を
if peek(word_list) == 'verb':
return match(word_list, 'verb')
else:
raise ParserError("Expected a verb next.")
DEF parse_object(WORD_LIST): (WORD_LIST、 '停止')スキップ next_word = PEEK(WORD_LIST)
if next_word == 'noun':
return match(word_list, 'noun')
elif next_word == 'direction':
return match(word_list, 'direction')
else:
raise ParserError("Expected a noun or direction next.")
DEF parse_subject(WORD_LIST): は(WORD_LIST、 '停止')スキップ next_word = PEEK(WORD_LIST)
if next_word == 'noun':
return match(word_list, 'noun')
elif next_word == 'verb':
return ('noun', 'player')
else:
raise ParserError("Expected a verb next.")
DEF parse_sentence(WORD_LIST): SUBJ = parse_subject(WORD_LIST) 動詞= parse_verb (WORD_LIST) OBJ = parse_object(WORD_LIST)
return Sentence(subj, verb, obj)
これは私のテストはファイルである
DEF test_subject()parsrer:( "/プロジェクト/ projectx48/ex48 H")
インポート: WORD_LIST = nose.toolsから
from nose.tools import *
はASSERT_EQUALS インポートSYS sys.path.appendをインポート assert_equals(parse_subject(word_list)、(( ''、 ''、 ''、 ''、 '') 'noun'、 'bear'))
あなたはどのようにそれをインポートしていますか? – levi