NutzCN Logo
问答 pyhone 一段代码
发布于 3338天前 作者 Rekoe 5240 次浏览 复制 上一个帖子 下一个帖子
标签: python
import uuid
import os.path
def processDirectory ( args, dirname, filenames ):
    for filename in filenames:
        print dirname,filename
        print uuid.uuid5(dirname, filename)

os.path.walk(r'/usr/local/resin/', processDirectory, None )
2 回复
/usr/local/resin/ contrib
Traceback (most recent call last):
  File "showFile.py", line 9, in <module>
    os.path.walk(r'/usr/local/resin/', processDirectory, None )
  File "/usr/local/lib/python2.7/posixpath.py", line 229, in walk
    func(arg, top, names)
  File "showFile.py", line 7, in processDirectory
    print uuid.uuid5(dirname, filename)
  File "/usr/local/lib/python2.7/uuid.py", line 552, in uuid5
    hash = sha1(namespace.bytes + name).digest()
AttributeError: 'str' object has no attribute 'bytes'

运行报这个错误

!/usr/bin/python

-*- coding: utf-8 -*-

import uuid
import os.path
def processDirectory ( args, dirname, filenames ):
for filename in filenames:
print dirname,filename
print uuid.uuid5(uuid.NAMESPACE_DNS, filename)
os.path.walk(r'/usr/local/resin/', processDirectory, None )

添加回复
请先登陆
回到顶部