James Thiele wrote: > I think the example: > > "My name is {0.name}".format(file('out.txt')) > > Would be easier to understand if you added: > > Which would produce: > > "My name is 'out.txt'"
I agree. Also, the example a couple of paragraphs down: "My name is {0[name]}".format(dict(name='Fred')) should show the expected output: "My name is Fred" I was adding test cases from the PEP last night, and I ignored the file one because I didn't want to mess with files. I've looked around for a replacement, but I couldn't find a built in type with an attribute that would be easy to test. Maybe we could stick with file, and use sys.stdin: "File name is {0.name}".format(sys.stdin) which would produce: 'File name is 0' I don't know if the "0" is platform dependent or not. If anyone has an example of a builtin (or standard module) type, variable, or whatever that has an attribute that can have a known value, I'd like to see it. When working on this, I notice that in 2.3.3 (on the same machine), sys.stdin.name is '<stdin>', but in py3k it's 0. Not sure if that's a bug or intentional. In any event, if we leave this example in the PEP, not only should we include the expected output, it should probably be changed to use "open" instead of "file": "My name is {0.name}".format(open('out.txt')) since I think file(filename) is deprecated (but still works). At least I thought it was deprecated, now that I look around I can't find any mention of it. Eric. _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com