Discuss / Python / 报错了

报错了

Topic source
# !/usr/bin/python
# -*- coding: utf-8 -*-

def now():
    print('2016-04-06')

f = now();

f

print(now.__name__)
print(f.__name__) # 这行报错

  File "/Users/Eagle/PycharmProjects/FastPlayer/EightPage.py", line 12, in <module>
    print(f.__name__)
AttributeError: 'NoneType' object has no attribute '__name__'

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

f=now()f=now是不同的!

Wooya君

#3 Created at ... [Delete] [Delete and Lock User]

f=now是将f指向now函数,而f=now()是将f指向now()返回值,now函数里没有定义返回值,所以默认返回值为None,None类型没有__name__属性


  • 1

Reply