python uuid奇怪的bug

dee*_*eko 2 python uuid

我首先尝试使用解释器用python的uuid模块生成uuid.我做了以下事情:

>>>import uuid
>>>uuid.uuid1()
UUID('d8904cf8-48ea-11e0-ac43-109add570b60')
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.我创建了一个简单的小函数来生成uuid.

import uuid

def get_guid():
    return uuid.uuid1()

if __name__ == '__main__':
    print get_guid()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

AttributeError:'module'对象没有属性'uuid1'

好的......嗯......回到口译员,现在它也被打破了.我得到相同的错误运行我用来测试它的相同代码.我很困惑.是什么让uuid像这样打破?我的代码出了什么问题?

我正在使用python 2.6

Mah*_*der 14

您的测试文件名很可能已命名 uuid.py

当您返回解释器时,您从同一目录启动了解释器,默认情况下,它将首先查找要在当前工作目录中导入的模块名称.

只需将测试文件名更改为其他名称,即 uuid_test_snippet.py