Re: strings and ints consistency - isinstance

2016-09-22 Thread Steve D'Aprano
On Thu, 22 Sep 2016 11:40 pm, Sayth Renshaw wrote: > True it failed, just actually happy to get it to fail or pass successfully > on int input. But it doesn't. It raises ValueError no matter what you enter. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure

Re: strings and ints consistency - isinstance

2016-09-22 Thread Larry Hudson via Python-list
On 09/22/2016 06:40 AM, Sayth Renshaw wrote: [snip...] True it failed, just actually happy to get it to fail or pass successfully on int input. Just felt it was a clearer and more consistent approach to verifying input, then most of the varied and rather inconsistent approaches I have seen

Re: strings and ints consistency - isinstance

2016-09-22 Thread Sayth Renshaw
> > This ends being the code I can use to get it to work, seems clear and > > pythonic, open to opinion on that :-) > > Neither clear, nor Pythonic. Sadly imo clearer than the many hack attempts on SO. > > > answer = input("\t >> ") > > Since input() returns a string in Python 3, this will

Re: strings and ints consistency - isinstance

2016-09-22 Thread Gregory Ewing
On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote: answer = input("\t >> ") if isinstance(int(answer), int) is True: raise ValueError("Ints aren't valid input") You seem to be trying to check that the user hasn't entered an integer. But that's a backwards way of

Re: strings and ints consistency - isinstance

2016-09-22 Thread Steve D'Aprano
On Thu, 22 Sep 2016 01:41 pm, Sayth Renshaw wrote: > This ends being the code I can use to get it to work, seems clear and > pythonic, open to opinion on that :-) Neither clear, nor Pythonic. > answer = input("\t >> ") Since input() returns a string in Python 3, this will always be a string.

Re: strings and ints consistency - isinstance

2016-09-22 Thread Ned Batchelder
On Wednesday, September 21, 2016 at 11:41:42 PM UTC-4, Sayth Renshaw wrote: > This ends being the code I can use to get it to work, seems clear and > pythonic, open to opinion on that :-) > > > answer = input("\t >> ") > if isinstance(int(answer), int) is True: > raise ValueError("Ints

Re: strings and ints consistency - isinstance

2016-09-22 Thread Lawrence D’Oliveiro
On Thursday, September 22, 2016 at 3:41:42 PM UTC+12, Sayth Renshaw wrote: > if isinstance(int(answer), int) is True: Not sure what the point of this is... -- https://mail.python.org/mailman/listinfo/python-list

Re: strings and ints consistency - isinstance

2016-09-21 Thread Sayth Renshaw
This ends being the code I can use to get it to work, seems clear and pythonic, open to opinion on that :-) answer = input("\t >> ") if isinstance(int(answer), int) is True: raise ValueError("Ints aren't valid input") sys.exit() elif isinstance(answer, str) is True: print(v0 * t

Re: strings and ints consistency - isinstance

2016-09-21 Thread Sayth Renshaw
To answer all the good replies. I adapted a simple vector example from the Springer book practical primer on science with python. Having solved the actual problem I thought checking with the user they had the correct entries or would like to ammend them would be a good addition. This leads to

Re: strings and ints consistency - isinstance

2016-09-21 Thread Steve D'Aprano
On Thu, 22 Sep 2016 12:26 am, Sayth Renshaw wrote: > Hi > > Trying to clarify why ints and strings arent treated the same. Because ints and strings are different? :-) > You can get a valuerror from trying to cast a non-int to an int as in > int(3.0) however you cannot do a non string with

Re: strings and ints consistency - isinstance

2016-09-21 Thread John Gordon
In Sayth Renshaw writes: > Trying to clarify why ints and strings arent treated the same. Because they are not the same. > You can get a valuerror from trying to cast a non-int to an int as in > int(3.0) however

Re: strings and ints consistency - isinstance

2016-09-21 Thread Ned Batchelder
On Wednesday, September 21, 2016 at 10:27:15 AM UTC-4, Sayth Renshaw wrote: > Hi > > Trying to clarify why ints and strings arent treated the same. > > You can get a valuerror from trying to cast a non-int to an int as in > int(3.0) however you cannot do a non string with str(a). > > Which