On 15Dec2015 17:11, Cameron Simpson <c...@zip.com.au> wrote:
On 14Dec2015 16:48, Vincent Davis <vinc...@vincentdavis.net> wrote:
[...]
I think the intent of the original code was to check if handle had the
attribute "name", I don't think the attribute "write" was the issue.
[...]
Secondly, for your use case "print the name if it has one" I _would_ use
hasattr:
if hasattr(handle, name):
write("# Report_file: %s\n" % name)
On reflection, there's also this:
name = getattr(handle, 'name', repr(handle))
write("# Report_file: %s\n" % name)
i.e. _always_ identfy the handle, even if it has no nice name.
Cheers,
Cameron Simpson <c...@zip.com.au>
--
https://mail.python.org/mailman/listinfo/python-list