开发者

python uuid weird bug

开发者 https://www.devze.com 2023-02-15 03:48 出处:网络
I first tried with the interpreter to produce uuid\'s with python\'s uuid module. I did the following:

I first tried with the interpreter to produce uuid's with python's uuid module. I did the following:

>>>import uuid
>>>uuid.uuid1()
UUID('d8904cf8-48ea-11e0-ac43-109add570b60')

So far so good. I create a simple little function to produce the uuid's.

import uuid

def get_guid():
    return uuid.uuid1()

if __n开发者_运维问答ame__ == '__main__':
    print get_guid()

and I get the following error:

AttributeError: 'module' object has no attribute 'uuid1'

Ok...hmm...go back to the interpreter and now it too is broken. I get the same error running the same code I used to test this. I am baffled. What makes uuid break like this? And what is wrong with my code?

I am using python 2.6


Your test file name is most likely named uuid.py

When you went back to the interpreter, you launched the interpreter from the same directory, which by default, will first look for the module name to import in your current working directory.

Just change your test file name to something else, i.e. uuid_test_snippet.py

0

精彩评论

暂无评论...
验证码 换一张
取 消