Re: Underscores in Python numbers

2005-11-21 Thread Antoon Pardon
Op 2005-11-20, Roy Smith schreef [EMAIL PROTECTED]: [EMAIL PROTECTED] (David M. Cooke) wrote: One example I can think of is a large number of float constants used for some math routine. In that case they usually be a full 16 or 17 digits. It'd be handy in that case to split into smaller

Re: Underscores in Python numbers

2005-11-21 Thread Scott David Daniels
Bruno Desthuilliers wrote: So even if it's far from a common use case for *most* Python users, it may be a common use case for *some* Python users. Also, someone mentionned the use of Python as a configuration langage - which is probably a much more common use case. So FWIW, I'd be +1

Re: Underscores in Python numbers

2005-11-21 Thread Micah Elliott
On Nov 19, Steven D'Aprano wrote: Perhaps Python should concatenate numeric literals at compile time: 123 456 is the same as 123456. +1 for readability. But in support of no change, When was the last time you looked at long sequences of python digits outside of your editor/IDE? You probably

Re: Underscores in Python numbers

2005-11-21 Thread Eric Jacoboni
[EMAIL PROTECTED] (Bengt Richter) writes: Eric Jacoboni, ne il y a 1435938104 secondes Um, about your sig ... ;-) Well, i confess it's Ruby code... Maybe, one day, i will try to write a Python Version (with DateTime, i guess?) but i'm afraid it doesn't change the result. -- Eric Jacoboni, ne

Re: Underscores in Python numbers

2005-11-20 Thread Dan Bishop
Roy Smith wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: That's a tad unfair. Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. There are plenty of ways to make numeric

Re: Underscores in Python numbers

2005-11-20 Thread Peter Hansen
Dan Bishop wrote: Roy Smith wrote: creditCardNumber = myInt (1234 5678 9012 3456 789) Or alternatively, you could write: creditCardNumber = int('1234''5678''9012''3456''789') Or creditCardNumber = int(1234 5678 9012 3456 789.replace(' ','')) Or make a little function that does the same

Re: Underscores in Python numbers

2005-11-20 Thread [EMAIL PROTECTED]
Peter Hansen wrote: But why would anyone want to create numeric literals for credit card numbers? May be for space saving ? But storage space being so cheap, this is not a very good reason, but still a reason. -- http://mail.python.org/mailman/listinfo/python-list

Re: Underscores in Python numbers

2005-11-20 Thread Eric Jacoboni
Mike Meyer [EMAIL PROTECTED] writes: I've seen at least one language (forget which one) that allowed such separators, but only for groups of three. So 123_456 would be valid, but 9_1 would be a syntax error. Ada allows underscores in numeric literals since 1983, without enforcing any

Re: Underscores in Python numbers

2005-11-20 Thread Steve Holden
David M. Cooke wrote: Peter Hansen [EMAIL PROTECTED] writes: Steven D'Aprano wrote: Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. I'm totally unconvinced that this _is_ a

Re: Underscores in Python numbers

2005-11-20 Thread Roy Smith
Dan Bishop [EMAIL PROTECTED] wrote: creditCardNumber = int('1234''5678''9012''3456''789') Wow, I didn't know you could do that. That's better than my idea. -- http://mail.python.org/mailman/listinfo/python-list

Re: Underscores in Python numbers

2005-11-20 Thread D H
Steve Holden wrote: David M. Cooke wrote: One example I can think of is a large number of float constants used for some math routine. In that case they usually be a full 16 or 17 digits. It'd be handy in that case to split into smaller groups to make it easier to match with tables where these

Re: Underscores in Python numbers

2005-11-20 Thread [EMAIL PROTECTED]
D H wrote: Steve Holden wrote: David M. Cooke wrote: One example I can think of is a large number of float constants used for some math routine. In that case they usually be a full 16 or 17 digits. It'd be handy in that case to split into smaller groups to make it easier to match with

Re: Underscores in Python numbers

2005-11-20 Thread Peter Hansen
[EMAIL PROTECTED] wrote: Peter Hansen wrote: But why would anyone want to create numeric literals for credit card numbers? May be for space saving ? But storage space being so cheap, this is not a very good reason, but still a reason. Space saving where? Why would you have any credit card

Re: Underscores in Python numbers

2005-11-20 Thread Roy Smith
[EMAIL PROTECTED] (David M. Cooke) wrote: One example I can think of is a large number of float constants used for some math routine. In that case they usually be a full 16 or 17 digits. It'd be handy in that case to split into smaller groups to make it easier to match with tables where these

Re: Underscores in Python numbers

2005-11-20 Thread Steven D'Aprano
On Sun, 20 Nov 2005 09:27:28 -0500, Peter Hansen wrote: But why would anyone want to create numeric literals for credit card numbers? Credit card numbers is not a sensible usage case. Neither are books' ISBNs, or tax file numbers, or telephone numbers -- these are all instances where it

Re: Underscores in Python numbers

2005-11-20 Thread Steven D'Aprano
On Sun, 20 Nov 2005 15:52:29 -0500, Roy Smith wrote: You have described, if memory serves, a Taylor series, and those coefficients are 1/3!, 1/5!, 1/7!, etc. What I would do, rather than embedding the numeric constants in the code, is embed the formula and have the machine compute the

Re: Underscores in Python numbers

2005-11-20 Thread Bruno Desthuilliers
Raymond Hettinger a écrit : Gustav Hållberg wrote: I tried finding a discussion around adding the possibility to have optional underscores inside numbers in Python. This is a popular option available in several competing scripting langauges, that I would love to see in Python. Examples

Re: Underscores in Python numbers

2005-11-20 Thread [EMAIL PROTECTED]
Peter Hansen wrote: [EMAIL PROTECTED] wrote: Peter Hansen wrote: But why would anyone want to create numeric literals for credit card numbers? May be for space saving ? But storage space being so cheap, this is not a very good reason, but still a reason. Space saving where? Why

Re: Underscores in Python numbers

2005-11-20 Thread Bengt Richter
On Sun, 20 Nov 2005 15:37:40 +, Steve Holden [EMAIL PROTECTED] wrote: David M. Cooke wrote: Peter Hansen [EMAIL PROTECTED] writes: Steven D'Aprano wrote: Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people

Re: Underscores in Python numbers

2005-11-20 Thread Bengt Richter
On Sun, 20 Nov 2005 15:50:10 +0100, Eric Jacoboni [EMAIL PROTECTED] wrote: Mike Meyer [EMAIL PROTECTED] writes: I've seen at least one language (forget which one) that allowed such separators, but only for groups of three. So 123_456 would be valid, but 9_1 would be a syntax error. Ada

Re: Underscores in Python numbers

2005-11-20 Thread Bengt Richter
On Sun, 20 Nov 2005 15:50:10 +0100, Eric Jacoboni [EMAIL PROTECTED] wrote: Mike Meyer [EMAIL PROTECTED] writes: I've seen at least one language (forget which one) that allowed such separators, but only for groups of three. So 123_456 would be valid, but 9_1 would be a syntax error. Ada

Re: Underscores in Python numbers

2005-11-20 Thread bearophileHUGS
Peter HansenOr maybe one should instead interpret this as numeric literals need more bells and whistles, and I don't care which of these two we add, but we have to do *something*!. :-) The purpose of my words was: when you think about adding a new syntax/functionality to a language, you have to

Re: Underscores in Python numbers

2005-11-19 Thread Stefan Rank
on 19.11.2005 06:56 Steven D'Aprano said the following: [snip] Perhaps Python should concatenate numeric literals at compile time: 123 456 is the same as 123456. Off the top of my head, I don't think this should break any older code, because 123 456 is not currently legal in Python. +1

Re: Underscores in Python numbers

2005-11-19 Thread bearophileHUGS
Steven D'Aprano: Perhaps Python should concatenate numeric literals at compile time: 123 456 is the same as 123456. I think using the underscore it is more explicit: n = 123_456 Alternatively the underscore syntax may be used to separate the number from its base: 22875 == 22875_10 == 595b_16

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Stefan Rank wrote: The other idea of teaching int() about separator characters has internationalis/zation issues: In many European countries, one would naturally try:: int('500.000,23') instead of:: int('500,000.23') That is why I said Of course, also support the locale variant

Re: Underscores in Python numbers

2005-11-19 Thread Steven D'Aprano
On Sat, 19 Nov 2005 01:33:40 -0800, bearophileHUGS wrote: Steven D'Aprano: Perhaps Python should concatenate numeric literals at compile time: 123 456 is the same as 123456. I think using the underscore it is more explicit: n = 123_456 It is also easy to make a typo: n = 123-456 --

Re: Underscores in Python numbers

2005-11-19 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with: Of course, also support the locale variant where the meaning of , and . is swapped in most European countries. This is exactly why I wouldn't use that notation. What happens if it is hardcoded into the source? I mean, that's what we're talking about. Then

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Sybren Stuvel wrote: [EMAIL PROTECTED] enlightened us with: Of course, also support the locale variant where the meaning of , and . is swapped in most European countries. This is exactly why I wouldn't use that notation. What happens if it is hardcoded into the source? I mean, that's what

Re: Underscores in Python numbers

2005-11-19 Thread Roy Smith
[EMAIL PROTECTED] wrote: Alternatively the underscore syntax may be used to separate the number from its base: 22875 == 22875_10 == 595b_16 == 123456_7 But probably this is less commonly useful (and not much explicit). We already have a perfectly good syntax for entering octal and hex

Re: Underscores in Python numbers

2005-11-19 Thread Steve Holden
[EMAIL PROTECTED] wrote: Stefan Rank wrote: The other idea of teaching int() about separator characters has internationalis/zation issues: In many European countries, one would naturally try:: int('500.000,23') instead of:: int('500,000.23') That is why I said Of course, also

Re: Underscores in Python numbers

2005-11-19 Thread bearophileHUGS
Roy SmithWe already have a perfectly good syntax for entering octal and hex integers, There is this syntax: 1536 == int(600, 16) that accepts strings only, up to a base of 36. There are the hex() and oct() functions. There is the %x and %o sintax, that isn't easy to remember. There are the 0x600

Re: Underscores in Python numbers

2005-11-19 Thread Peter Hansen
[EMAIL PROTECTED] wrote: Steven D'Aprano: Perhaps Python should concatenate numeric literals at compile time: 123 456 is the same as 123456. I think using the underscore it is more explicit: n = 123_456 Alternatively the underscore syntax may be used to separate the number from its base:

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Steve Holden wrote: [EMAIL PROTECTED] wrote: Stefan Rank wrote: The other idea of teaching int() about separator characters has internationalis/zation issues: In many European countries, one would naturally try:: int('500.000,23') instead of:: int('500,000.23') That

Re: Underscores in Python numbers

2005-11-19 Thread Steve Holden
[EMAIL PROTECTED] wrote: Steve Holden wrote: [...] I really wouldn't want it to become possible to write Python code in one locale that had to be edited before the numeric literals were valid in another locale. That way madness lies. That is the fact, from the very beginning. 1.234 striaightly

Re: Underscores in Python numbers

2005-11-19 Thread Steven D'Aprano
On Sat, 19 Nov 2005 13:08:57 -0500, Peter Hansen wrote: Umm... in other words, the underscore is under-used so let's assign some arbitrary meaning to it (to make the language more like Perl perhaps?). +1 I *really* don't like the idea of allowing underscores in numeric literals. Firstly,

Re: Underscores in Python numbers

2005-11-19 Thread Steve Holden
Steven D'Aprano wrote: [...] Likewise, base conversion into arbitrary bases is not, in my opinion, common enough a task that support for it needs to be built into the syntax for literals. If somebody cares enough about it, write a module to handle it and try to get it included with the Python

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Steve Holden wrote: Being European myself I am well aware of the notational differences of the different locales, and I am perfectly happy that users can enter numbers in their preferred format when they execute a program. However, I am not happy about the idea that a program source would

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: That's a tad unfair. Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. In the wider world outside of IT, people deal with long numeric digits by grouping.

Re: Underscores in Python numbers

2005-11-19 Thread Steven D'Aprano
On Sun, 20 Nov 2005 01:39:04 +, Steve Holden wrote: Steven D'Aprano wrote: [...] Likewise, base conversion into arbitrary bases is not, in my opinion, common enough a task that support for it needs to be built into the syntax for literals. If somebody cares enough about it, write a

Re: Underscores in Python numbers

2005-11-19 Thread Peter Hansen
Steven D'Aprano wrote: Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. I'm totally unconvinced that this _is_ a real problem, if we define real as being even enough to jiggle my

Re: Underscores in Python numbers

2005-11-19 Thread Roy Smith
Steven D'Aprano [EMAIL PROTECTED] wrote: That's a tad unfair. Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. There are plenty of ways to make numeric literals easier to read

Re: Underscores in Python numbers

2005-11-19 Thread Mike Meyer
Steven D'Aprano [EMAIL PROTECTED] writes: On Sat, 19 Nov 2005 13:08:57 -0500, Peter Hansen wrote: Umm... in other words, the underscore is under-used so let's assign some arbitrary meaning to it (to make the language more like Perl perhaps?). +1 I *really* don't like the idea of allowing

Re: Underscores in Python numbers

2005-11-19 Thread Roy Smith
Mike Meyer [EMAIL PROTECTED] wrote: I've seen at least one language (forget which one) that allowed such separators, but only for groups of three. That seems a bit silly. Not all numbers are naturally split into groups of three. Credit card numbers are (typically) split into groups of four.

Re: Underscores in Python numbers

2005-11-19 Thread Raymond Hettinger
Gustav Hållberg wrote: I tried finding a discussion around adding the possibility to have optional underscores inside numbers in Python. This is a popular option available in several competing scripting langauges, that I would love to see in Python. Examples: 1_234_567 0xdead_beef

Re: Underscores in Python numbers

2005-11-19 Thread Mike Meyer
Roy Smith [EMAIL PROTECTED] writes: Mike Meyer [EMAIL PROTECTED] wrote: I've seen at least one language (forget which one) that allowed such separators, but only for groups of three. That seems a bit silly. Not all numbers are naturally split into groups of three. Credit card numbers are

Re: Underscores in Python numbers

2005-11-19 Thread David M. Cooke
Peter Hansen [EMAIL PROTECTED] writes: Steven D'Aprano wrote: Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. I'm totally unconvinced that this _is_ a real problem, if we

Re: Underscores in Python numbers

2005-11-18 Thread Dave Hansen
Sorry for the delayed response. I somehow missed this earlier. On Tue, 8 Nov 2005 15:39:09 + (UTC) in comp.lang.python, [EMAIL PROTECTED] (Roy Smith) wrote: Dave Hansen [EMAIL PROTECTED] wrote: Of course, I write _far_ more code in C than Python. But I've seen enough bugs of the sort

Re: Underscores in Python numbers

2005-11-18 Thread [EMAIL PROTECTED]
around adding the possibility to have optional underscores inside numbers in Python. This is a popular option available in several competing scripting langauges, that I would love to see in Python. Examples: 1_234_567 0xdead_beef 3.141_592 Would appreciate if someone could find

Re: Underscores in Python numbers

2005-11-18 Thread Steven D'Aprano
On Fri, 18 Nov 2005 16:26:08 -0800, [EMAIL PROTECTED] wrote: Personally, I would rather see the int() and float() function be smarter to take what is used for this, i.e. : a = int(1,234,567) But the problem isn't just with conversion of strings. It is also with literals. n = 999

Re: Underscores in Python numbers

2005-11-18 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: On Fri, 18 Nov 2005 16:26:08 -0800, [EMAIL PROTECTED] wrote: Personally, I would rather see the int() and float() function be smarter to take what is used for this, i.e. : a = int(1,234,567) But the problem isn't just with conversion of strings. It is also with

Re: Underscores in Python numbers

2005-11-08 Thread Dave Hansen
On 7 Nov 2005 18:02:09 -0800 in comp.lang.python, Gustav Hållberg [EMAIL PROTECTED] wrote: I tried finding a discussion around adding the possibility to have optional underscores inside numbers in Python. This is a popular option available in several competing scripting langauges, that I would

Re: Underscores in Python numbers

2005-11-08 Thread Roy Smith
Dave Hansen [EMAIL PROTECTED] wrote: Of course, I write _far_ more code in C than Python. But I've seen enough bugs of the sort where someone wrote 120 when they meant 1200, that I see great value in being able to specify 12_000_000. I'll admit that being able to write 12_000_000

Underscores in Python numbers

2005-11-07 Thread Gustav Hållberg
I tried finding a discussion around adding the possibility to have optional underscores inside numbers in Python. This is a popular option available in several competing scripting langauges, that I would love to see in Python. Examples: 1_234_567 0xdead_beef 3.141_592 Would appreciate

Re: Underscores in Python numbers

2005-11-07 Thread Devan L
Gustav Hållberg wrote: I tried finding a discussion around adding the possibility to have optional underscores inside numbers in Python. This is a popular option available in several competing scripting langauges, that I would love to see in Python. Examples: 1_234_567 0xdead_beef

Re: Underscores in Python numbers

2005-11-07 Thread Peter Hansen
Gustav Hållberg wrote: I tried finding a discussion around adding the possibility to have optional underscores inside numbers in Python. This is a popular option available in several competing scripting langauges, that I would love to see in Python. Examples: 1_234_567 0xdead_beef