On 10/14/2011 9:51 PM, Ben Finney wrote:
Terry Reedy<tjre...@udel.edu>  writes:

On 10/14/2011 9:05 PM, Chris Angelico wrote:

That tests if the object is already an int; the OP asked if a string
contains an integer.

The misleading subject line did not. It should have been "How to test
if a string contains an integer?"

Which would still be misleading :-)

Even better is “How to test whether a string is a valid representation
of an integer?”

I agree, but that is more than I would ask of a newbie, whereas asking people to ask the same question in subject line and text, even if the question is inadequate, is reasonable.

I say that's better because it gets to the relevant point of asking
*which* representations you want to test for – what qualifies as valid
for your particular use case, and what does not. There's no single right
answer; the programmer must choose exactly what they want to test for.

Yes. Even the wrong subject line question is ambiguous, as any of int, bool, float, complex, decimal.Decimal, and fractions.Fraction can have an integer value, as might user class instances, and, of course, depending on context, bytes and strings.

--
Terry Jan Reedy


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to