Python 打印目录(XXX)给出空白属性

Python 打印目录(XXX)给出空白属性,python,list,xlsx,Python,List,Xlsx,简言之,我使用一个xlsx文件,在使用print diralist检查一些列表时,获取空白属性 neglist = neglist.tolist() 此时,我想检查evth是否正常: def check_variab (variab): print "The type is %s" % type(variab) print "Its length = %i" % len(variab) print "Its attributes are:" % dir(variab)

简言之,我使用一个xlsx文件,在使用print diralist检查一些列表时,获取空白属性

neglist = neglist.tolist()
此时,我想检查evth是否正常:

def check_variab (variab):
    print "The type is %s" % type(variab)
    print "Its length = %i" % len(variab)
    print "Its attributes are:" % dir(variab)

print 'neglist'
check_variab(neglist)
但我得到的是:

type: list
length: 19
attributes: 
没有打印属性,尽管类型是list ok,其长度和内容是ok

有人能解释一下为什么会发生这种情况吗?

您忘了使用%s占位符,因此不会插入任何内容。添加%s或%r:

如果没有占位符,您将看不到任何内容,事实上:

>>> variab = ['foo', 'bar']
>>> dir(variab)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> print "Its attributes are:" % dir(variab)
Its attributes are:
>>> print "Its attributes are %s:" % dir(variab)
Its attributes are ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']:

您想在列表中使用。

您的输出是文本,请不要使用屏幕截图,复制文本并粘贴到此处。在Windows控制台中,[-]窗口菜单具有可在此处使用的复制控件。请原谅我的愚蠢,[-]窗口菜单是什么?老实说,我试图找到它,但失败了…它是所有窗口上的默认窗口菜单;现在右键单击菜单栏时,菜单似乎已更改为显示的菜单。我真丢脸!谢谢
>>> variab = ['foo', 'bar']
>>> dir(variab)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> print "Its attributes are:" % dir(variab)
Its attributes are:
>>> print "Its attributes are %s:" % dir(variab)
Its attributes are ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']: