[issue32163] getattr() returns None even when default is given

2017-11-29 Thread Raymond Hettinger
Change by Raymond Hettinger : -- status: open -> closed ___ Python tracker ___

[issue32163] getattr() returns None even when default is given

2017-11-28 Thread Steven D'Aprano
Steven D'Aprano added the comment: That's not a bug. That's because the file object does have an encoding attribute, which is set to None. getattr only returns the default when the attribute doesn't exist, not if it exists but is None. -- nosy:

[issue32163] getattr() returns None even when default is given

2017-11-28 Thread darkdragon-001
New submission from darkdragon-001 : # fail.py def main(): patch = './a' f = open(patch, 'r') a = getattr(f,'encoding','ascii') print(str(a)) if __name__ == "__main__": main() --- $ touch a $ python fail.py It still prints out 'None' instead of