NameError:未定义全局名称'inner'(但实际上并非如此)

时间:2014-09-20 01:38:55

标签: python

我收到标题中描述的非常简单模块的错误。我不知道为什么它没有运行。我正确设置了我的目录,并将一个字符串传递给定义的函数,但它似乎无法越过该行

q1 = s.find('"')+1

这是我尝试运行以下功能的模块:

def has_a_vowel(s):
    """Returns: True if s has at least one vowel (a, e, i, o, or u)

    Precondition: s is a non-empty string"""
    return 'a' in s and 'e' in s and 'i' in s and 'o' in s and 'u' in s


def first_inside_quotes(s):
    """Returns: The first substring of s between two (double) quote characters

    Example: If s is 'A "B C" D', this function returns 'B C'
    Example: If s is 'A "B C" D "E F" G', this function still returns 'B C'
    because it only picks the first such substring.

    Precondition: s is a string with at least two (double) quote characters inside"""
    # Your assignment statements from lab 2 here

    q1 = s.find('"')+1
    print q1
    s2 = s[q1:]
    q2 = s2.find('"') + q1

    inner= s[q1:q2]

    return inner

1 个答案:

答案 0 :(得分:0)

评论的人是正确的;该错误不能来自我发布的代码。

所以事实证明我必须在命令窗口中退出()python然后再次启动python。显然我不能在我保存对代码的更改之后再次导入我的lab02模块...这真的很愚蠢,但退出python并重新启动它然后再次导入模块工作。