[docs] [issue20598] argparse docs: '7'.split() is confusing magic
report at bugs.python.org
Fri Aug 8 00:20:19 CEST 2014
paul j3 added the comment:
For documentation, ['this','is','a','test'] might be a bit clearer than 'this is a test'.split(). But generating a list of strings by split is, I think, a pretty basic idiom.
But for testing purposes the split() version is a bit more robust because it is closer to what might appear in sys.argv.
In : ['this','is','a','test'][-1] is 'test'
In : 'this is a test'.split()[-1] is 'test'
That is, the 'id' of a string generated by a split is not the same as that of an explicit string. sys.argv is created by a split in the shell and/or the interpreter, so it too will fail this 'is' test.
Python tracker <report at bugs.python.org>
More information about the docs