Re: Integers with leading zeroes
Michael Torrie wrote: A credit card number is indeed a number, and there are mathematical formulas for determining if a particular number is a valid (as in well-formed) credit card number, If you're talking about the check-digit algorithm, that doesn't treat the whole number as an integer, it works on the individual digits: http://www.datagenetics.com/blog/july42013/ and possibly to identify what kind of card it is. That's determined by the leading digits, and can be done just as well by treating them as characters. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Fri, Jul 24, 2015 at 4:23 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Michael Torrie wrote: A credit card number is indeed a number, and there are mathematical formulas for determining if a particular number is a valid (as in well-formed) credit card number, If you're talking about the check-digit algorithm, that doesn't treat the whole number as an integer, it works on the individual digits: http://www.datagenetics.com/blog/july42013/ and possibly to identify what kind of card it is. That's determined by the leading digits, and can be done just as well by treating them as characters. So, the definition of a number is: Something on which you perform numeric operations. Aside from being circular, wouldn't this mean that rope is a number, since its square root is string? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Wed, 22 Jul 2015 20:11:47 -0600, Michael Torrie wrote: On 07/22/2015 07:51 AM, Grant Edwards wrote: On 2015-07-22, Ben Finney ben+pyt...@benfinney.id.au wrote: Laura Creighton l...@openend.se writes: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. The following are examples of types from the real world that people think of, and casually discuss, as “numbers”. * Postal code * Credit card number * Telephone number * Car registration plate number * Personal Identification Number (PIN) Those are all strings. Not numbers. That depends. A credit card number is indeed a number, and there are mathematical formulas for determining if a particular number is a valid (as in well-formed) credit card number, and possibly to identify what kind of card it is. no it is a string,that happens to be made up out of digits. the digits can be manipulated but you do not perform maths on a credit card number as a whole -- Did I do an INCORRECT THING?? -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 07/22/2015 07:51 AM, Grant Edwards wrote: On 2015-07-22, Ben Finney ben+pyt...@benfinney.id.au wrote: Laura Creighton l...@openend.se writes: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. The following are examples of types from the real world that people think of, and casually discuss, as “numbers”. * Postal code * Credit card number * Telephone number * Car registration plate number * Personal Identification Number (PIN) Those are all strings. Not numbers. That depends. A credit card number is indeed a number, and there are mathematical formulas for determining if a particular number is a valid (as in well-formed) credit card number, and possibly to identify what kind of card it is. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 2015-07-22, Antoon Pardon antoon.par...@rece.vub.ac.be wrote: Does the same condition hold for strings? If you are not performing string operations on something, it is not a string? If you never need to do any string operations on it then you should not be using a string. -- Grant Edwards grant.b.edwardsYow! The PINK SOCKS were at ORIGINALLY from 1952!! gmail.comBut they went to MARS around 1953!! -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 2015-07-22 16:50, Grant Edwards wrote: On 2015-07-22, MRAB pyt...@mrabarnett.plus.com wrote: On 2015-07-22 16:27, Antoon Pardon wrote: Does the same condition hold for strings? If you are not performing string operations on something, it is not a string? Tkinter comes to mind. You specify how widgets are laid out strings that are basically flags: text_widget.pack(side=LEFT, fill=BOTH, expand=YES) where LEFT, BOTH and YES are strings. That's Tcl's fault. They have to be passed to Tcl, and Tcl only has one data type: strings. But _I'm_ writing in Python. Do I have to know how Tcl works underneath? -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 2015-07-22, Steven D'Aprano st...@pearwood.info wrote: On Wed, 22 Jul 2015 11:51 pm, Grant Edwards wrote: On 2015-07-22, Ben Finney ben+pyt...@benfinney.id.au wrote: Laura Creighton l...@openend.se writes: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. The following are examples of types from the real world that people think of, and casually discuss, as “numbers”. * Postal code * Credit card number * Telephone number * Car registration plate number * Personal Identification Number (PIN) Those are all strings. Not numbers. I'm pretty sure that was Ben's point :-) Ah yes, now I see it was. -- Grant Edwards grant.b.edwardsYow! HELLO, everybody, at I'm a HUMAN!! gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Wed, 22 Jul 2015 11:51 pm, Grant Edwards wrote: On 2015-07-22, Ben Finney ben+pyt...@benfinney.id.au wrote: Laura Creighton l...@openend.se writes: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. The following are examples of types from the real world that people think of, and casually discuss, as “numbers”. * Postal code * Credit card number * Telephone number * Car registration plate number * Personal Identification Number (PIN) Those are all strings. Not numbers. I'm pretty sure that was Ben's point :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 07/22/2015 11:09 AM, alister wrote: On Wed, 22 Jul 2015 09:12:59 +0200, Laura Creighton wrote: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. So far, all the examples I've been able to find in my code -- which does this sort of stuff a lot -- is looking at string versions of decimal numbers, but I suspect there is old code out there in the wild which just used integers. Laura This type of information should be stored as a string not any type of numeric format, if you are not performing maths on it then it is a string not a number. Does the same condition hold for strings? If you are not performing string operations on something, it is not a string? -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 2015-07-22, MRAB pyt...@mrabarnett.plus.com wrote: On 2015-07-22 16:27, Antoon Pardon wrote: Does the same condition hold for strings? If you are not performing string operations on something, it is not a string? Tkinter comes to mind. You specify how widgets are laid out strings that are basically flags: text_widget.pack(side=LEFT, fill=BOTH, expand=YES) where LEFT, BOTH and YES are strings. That's Tcl's fault. They have to be passed to Tcl, and Tcl only has one data type: strings. -- Grant Edwards grant.b.edwardsYow! An INK-LING? Sure -- at TAKE one!! Did you BUY any gmail.comCOMMUNIST UNIFORMS?? -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 2015-07-22 16:27, Antoon Pardon wrote: On 07/22/2015 11:09 AM, alister wrote: On Wed, 22 Jul 2015 09:12:59 +0200, Laura Creighton wrote: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. So far, all the examples I've been able to find in my code -- which does this sort of stuff a lot -- is looking at string versions of decimal numbers, but I suspect there is old code out there in the wild which just used integers. Laura This type of information should be stored as a string not any type of numeric format, if you are not performing maths on it then it is a string not a number. Does the same condition hold for strings? If you are not performing string operations on something, it is not a string? Tkinter comes to mind. You specify how widgets are laid out strings that are basically flags: text_widget.pack(side=LEFT, fill=BOTH, expand=YES) where LEFT, BOTH and YES are strings. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
I wonder if bitcoin miners and other cryptological users need the leading 0s. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Wed, 22 Jul 2015 09:12:59 +0200, Laura Creighton wrote: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. So far, all the examples I've been able to find in my code -- which does this sort of stuff a lot -- is looking at string versions of decimal numbers, but I suspect there is old code out there in the wild which just used integers. Laura This type of information should be stored as a string not any type of numeric format, if you are not performing maths on it then it is a string not a number. anyone doing anything else is heading or the front page on www.thedailywtf.com :-) -- Everybody likes a kidder, but nobody lends him money. -- Arthur Miller -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
Laura Creighton l...@openend.se writes: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. The following are examples of types from the real world that people think of, and casually discuss, as “numbers”. * Postal code * Credit card number * Telephone number * Car registration plate number * Personal Identification Number (PIN) You can no doubt come up with other examples. Despite that they are represented in text with digits, and the authority that generates them may even use some sequence of integers, the types should not be treated as numbers. They are not quantities. Performing arithmetic on them (adding two together, dividing by two, etc.) makes no sense. Representing them in a different number base (e.g. hexadecimal) utterly changes their meaning. And, as you've found, a leading zero makes a difference to the value. To a computer (ignoring the legacy of octal representation), that makes nonsense of the idea these are numbers. So these types are not numbers and should not be treated that way in the program. These are, from the point of view of your computer program, opaque tokens. They should be encoded not using a number type, but a type which represents them as only a string of decimal digits. Best if they're stored without spaces or punctuation; convert to and from some format for human use if you must, but only at the input/output borders of the program. So far, all the examples I've been able to find in my code -- which does this sort of stuff a lot -- is looking at string versions of decimal numbers, but I suspect there is old code out there in the wild which just used integers. Maybe so, but I consider the latter kind of code to be a terrible practice since it leads to assumptions in the code which are unfounded, and which no human would ever make. Treat them the way a human actually would: as an opaque tokem, a text (sequence of characters) that happen to contain digits. -- \“Simplicity is prerequisite for reliability.” —Edsger W. | `\ Dijkstra | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. So far, all the examples I've been able to find in my code -- which does this sort of stuff a lot -- is looking at string versions of decimal numbers, but I suspect there is old code out there in the wild which just used integers. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
Laura Creighton l...@openend.se: What I want to know is why is 'huoneen numero' 2 words? rummets nummer Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
Ben Finney ben+pyt...@benfinney.id.au: Despite that they are represented in text with digits, and the authority that generates them may even use some sequence of integers, the types should not be treated as numbers. Let's just say that the word number has multiple meanings. Words with many meanings often lead to confusion. My native Finnish luckily has distinct words for the two things: luku (a quantity) and numero (a digit, numeral or label): luonnollinen luku (natural number) kokonaisluku (integer) rationaaliluku(rational number) reaaliluku(real number) kompleksiluku (complex number) liukuluku (floating-point number) desimaaliluku (decimal number) puhelinnumero (telephone number) rekisterinumero (registration number, license plate number) tilinumero(account number) huoneen numero(room number) sarjanumero (serial number) tuotenumero (product number) Obviously, the words liukuluku and desimaaliluku slide into the realms of numerals, but nevertheless, they deal with quantification rather than identification. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
In a message of Wed, 22 Jul 2015 12:10:55 +0300, Marko Rauhamaa writes: My native Finnish luckily has distinct words for the two things: luku (a quantity) and numero (a digit, numeral or label): luonnollinen luku (natural number) kokonaisluku (integer) rationaaliluku(rational number) reaaliluku(real number) kompleksiluku (complex number) liukuluku (floating-point number) desimaaliluku (decimal number) puhelinnumero (telephone number) rekisterinumero (registration number, license plate number) tilinumero(account number) huoneen numero(room number) sarjanumero (serial number) tuotenumero (product number) Obviously, the words liukuluku and desimaaliluku slide into the realms of numerals, but nevertheless, they deal with quantification rather than identification. Marko What I want to know is why is 'huoneen numero' 2 words? Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
Permitting leading 0s may make it harder to port Python 2 projects to Python 3. 010 == 8 (Python 2) 010 == 10 (Python 3.x) SyntaxError is very important for porting code. So I'm -1 on permitting leading 0s for decimal numbers. I think original question is for leading 0s for only 0. Not for arbitrarily decimals. On Wed, Jul 22, 2015 at 2:21 AM, Antoon Pardon antoon.par...@rece.vub.ac.be wrote: On 07/19/2015 07:39 AM, Steven D'Aprano wrote: In Python 2, integer literals with leading zeroes are treated as octal, so 09 is a syntax error and 010 is 8. This is confusing to those not raised on C-style octal literals, so in Python 3 leading zeroes are prohibited in int literals. Octal is instead written using the prefix 0o, similar to hex 0x and binary 0b. Consequently Python 3 makes both 09 and 010 a syntax error. However there is one exception: zero itself is allowed any number of leading zeroes, so 0 is a legal way to write zero as a base-10 int literal. Does anyone use that (mis)feature? Yes. I like to sometime write numbers with leading zeros. Sometimes these numbers represent codeblocks of a fixed number of digits. Always writing those numbers with this number of digits helps being aware of this. It is also easier for when you need to know how many leading zero's such a number has. -- https://mail.python.org/mailman/listinfo/python-list -- INADA Naoki songofaca...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 2015-07-22, Ben Finney ben+pyt...@benfinney.id.au wrote: Laura Creighton l...@openend.se writes: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. The following are examples of types from the real world that people think of, and casually discuss, as “numbers”. * Postal code * Credit card number * Telephone number * Car registration plate number * Personal Identification Number (PIN) Those are all strings. Not numbers. -- Grant Edwards grant.b.edwardsYow! does your DRESSING at ROOM have enough ASPARAGUS? gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Thu, Jul 23, 2015 at 1:38 AM, MRAB pyt...@mrabarnett.plus.com wrote: Does the same condition hold for strings? If you are not performing string operations on something, it is not a string? Tkinter comes to mind. You specify how widgets are laid out strings that are basically flags: text_widget.pack(side=LEFT, fill=BOTH, expand=YES) where LEFT, BOTH and YES are strings. The nearest term I can come up with here is that those three are *atoms*. They might be implemented as integers (most C-style APIs work that way), or as strings (which is apparently the case in Tkinter), or as instances of object() that exist solely so their identities can be checked (Python function default arguments are often done that way), but there's only one operation you're allowed to do: Ask if one atom is identical to another atom. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Wednesday, July 22, 2015 at 7:21:29 PM UTC+5:30, Grant Edwards wrote: On 2015-07-22, Ben Finney wrote: Laura Creighton writes: The biggest use I have for decimal numbers that begin with 0 is in credit card numbers, account numbers and the like where the first check you do is 'does this thing have the correct number of digits'. The following are examples of types from the real world that people think of, and casually discuss, as numbers. * Postal code * Credit card number * Telephone number * Car registration plate number * Personal Identification Number (PIN) Those are all strings. Not numbers. Cobol would represent these well (if I remember rightly) as PIC 9(n) USAGE DISPLAY The USAGE DISPLAY was the default and unnecessary to state explicitly whereas the alternative USAGE COMP(UTATIONAL) corresponds to what most post-COBOL programmers think of as (binary) numbers. [Just sayin'... NOT asking for python to have 'usage display' ints] -- https://mail.python.org/mailman/listinfo/python-list
Re: Address field [was: Integers with leading zeroes]
On Wed, Jul 22, 2015 at 2:31 PM, Jason Friedman jsf80...@gmail.com wrote: Of course, most of the time, I advocate a single multi-line text field Address, and let people key them in free-form. No postcode field whatsoever. I'm curious about that statement. I could see accepting input as you describe above, but I'm thinking you'd want to *store* a postcode field. Actually, no. Apart from statisticking, there's not a lot I can do with a postcode. Due to the nature of international addressing, it's usually safest to go to one extreme or the other: either full-on address validation that knows about every delivery point in every nation that you support (viable if you support only one country, and that country's postal service offers an API - happens here in Australia), or no validation whatsoever, and a simple free-form field for people to enter what they will. Most of the times I've been setting things up, they're too low-end to justify the former, so I recommend the latter. Sure, there might be typos... but there might be those anyway, with a classic multi-part form. (I do recommend having a drop-down select box for the country, incidentally. That's easily validated.) Storing postcodes works nicely once you've settled that they're all part of a single country. When you want to do statistics on postcodes, it's not usually too hard to rip them out of the blob and work with them, but they're unreliable anyway unless you've gone the full-on validation route. So I tend to just not do the stats at all :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 07/19/2015 07:39 AM, Steven D'Aprano wrote: In Python 2, integer literals with leading zeroes are treated as octal, so 09 is a syntax error and 010 is 8. This is confusing to those not raised on C-style octal literals, so in Python 3 leading zeroes are prohibited in int literals. Octal is instead written using the prefix 0o, similar to hex 0x and binary 0b. Consequently Python 3 makes both 09 and 010 a syntax error. However there is one exception: zero itself is allowed any number of leading zeroes, so 0 is a legal way to write zero as a base-10 int literal. Does anyone use that (mis)feature? Yes. I like to sometime write numbers with leading zeros. Sometimes these numbers represent codeblocks of a fixed number of digits. Always writing those numbers with this number of digits helps being aware of this. It is also easier for when you need to know how many leading zero's such a number has. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On 7/21/2015 10:58 AM, sohcahto...@gmail.com wrote: IMO, leading zeroes just looks like visual noise, and if I wanted to align numbers, I'd just use spaces. Aligning numbers using spaces doesn't always align -- using zeros does. Emile -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Tuesday, July 21, 2015 at 10:22:44 AM UTC-7, Antoon Pardon wrote: On 07/19/2015 07:39 AM, Steven D'Aprano wrote: In Python 2, integer literals with leading zeroes are treated as octal, so 09 is a syntax error and 010 is 8. This is confusing to those not raised on C-style octal literals, so in Python 3 leading zeroes are prohibited in int literals. Octal is instead written using the prefix 0o, similar to hex 0x and binary 0b. Consequently Python 3 makes both 09 and 010 a syntax error. However there is one exception: zero itself is allowed any number of leading zeroes, so 0 is a legal way to write zero as a base-10 int literal. Does anyone use that (mis)feature? Yes. I like to sometime write numbers with leading zeros. Sometimes these numbers represent codeblocks of a fixed number of digits. Always writing those numbers with this number of digits helps being aware of this. It is also easier for when you need to know how many leading zero's such a number has. IMO, leading zeroes just looks like visual noise, and if I wanted to align numbers, I'd just use spaces. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Wed, Jul 22, 2015 at 10:55 AM, Steven D'Aprano st...@pearwood.info wrote: Sometimes these numbers represent codeblocks of a fixed number of digits. Always writing those numbers with this number of digits helps being aware of this. It is also easier for when you need to know how many leading zero's such a number has. I'm not sure what you mean here. Python ints don't have a fixed number of digits. Sometimes your numbers carry specific payloads or structures. A few examples: Date: 20150722 [decimal] Unix permissions: 10777 [octal] MAC address: 0014a466fba9 [hex] In the MAC address example, it doesn't make sense to elide the leading zeroes. I can't currently think of a common, real-world example that uses decimal and isn't gong to push itself to the full eight digits, apart from Northern Territory postcodes with their silly 08nn pattern, but I'm sure they exist. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Address field [was: Integers with leading zeroes]
Of course, most of the time, I advocate a single multi-line text field Address, and let people key them in free-form. No postcode field whatsoever. I'm curious about that statement. I could see accepting input as you describe above, but I'm thinking you'd want to *store* a postcode field. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Wed, 22 Jul 2015 11:10 am, Chris Angelico wrote: On Wed, Jul 22, 2015 at 10:55 AM, Steven D'Aprano st...@pearwood.info wrote: Sometimes these numbers represent codeblocks of a fixed number of digits. Always writing those numbers with this number of digits helps being aware of this. It is also easier for when you need to know how many leading zero's such a number has. I'm not sure what you mean here. Python ints don't have a fixed number of digits. Sometimes your numbers carry specific payloads or structures. A few examples: Date: 20150722 [decimal] Unix permissions: 10777 [octal] MAC address: 0014a466fba9 [hex] I don't see the relevance of any of those examples. Only the date is kinda-sort in decimal, the others are in octal and hex and so need to be written as octal or hex numbers: perm = 0o10777 # not 25031 as the above will give addr = 0x0014a466fba9 # the above will give a syntax error The date example should be a string, not an integer. today = 20151231 tomorrow = today + 1 assert tomorrow == 20160101 # fails I guess you can have 0 as Unix permissions, there might even be a 0 MAC address, but would you write them in decimal as (etc.) when all the other perms and addresses are written in oct or hex? addresses = [ 0x0014a466fba9, 0x0014a00b3fb1, , 0x003744a9012a, ] In the MAC address example, it doesn't make sense to elide the leading zeroes. I can't currently think of a common, real-world example that uses decimal and isn't gong to push itself to the full eight digits, apart from Northern Territory postcodes with their silly 08nn pattern, but I'm sure they exist. Postcodes, or zip codes, also should be written as strings, even if they happen to be all digits. I'm still looking for an example of where somebody would write the int zero in decimal using more than one 0-digit. While I'm sure they are fascinating in and of themselves, examples of numbers written as strings, in hex or octal, non-zero numbers written without leading zeroes, or zero written with only a single digit don't interest me :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Wed, Jul 22, 2015 at 12:14 PM, Steven D'Aprano st...@pearwood.info wrote: On Wed, 22 Jul 2015 11:10 am, Chris Angelico wrote: On Wed, Jul 22, 2015 at 10:55 AM, Steven D'Aprano st...@pearwood.info wrote: Sometimes these numbers represent codeblocks of a fixed number of digits. Always writing those numbers with this number of digits helps being aware of this. It is also easier for when you need to know how many leading zero's such a number has. I'm not sure what you mean here. Python ints don't have a fixed number of digits. Sometimes your numbers carry specific payloads or structures. A few examples: Date: 20150722 [decimal] Unix permissions: 10777 [octal] MAC address: 0014a466fba9 [hex] I don't see the relevance of any of those examples. Only the date is kinda-sort in decimal, the others are in octal and hex and so need to be written as octal or hex numbers: perm = 0o10777 # not 25031 as the above will give addr = 0x0014a466fba9 # the above will give a syntax error Right, I'm just giving examples of structured numbers. I don't have a good example of a decimal structured number, but there are good examples in other bases, and the possibility is there for someone to have one that makes sense in decimal. The date example should be a string, not an integer. today = 20151231 tomorrow = today + 1 assert tomorrow == 20160101 # fails All that proves is that there are certain operations that don't work on date-stored-as-integer. The same operations equally won't work on date-stored-as-string. If you want date arithmetic, you MUST use a proper date/time library; but if all you want is simple and efficient comparisons, integers work fine. So do strings, but integers are right-justified. If you imagine a situation in which it's not dates with four digit years, but some other starting figure - maybe it's the year in some arbitrary calendar on which today is the 6th of Cuspis in the year 411 of the Common Reckoning. Those dates can go back before year 100, so the date numbers would lose a digit compared to today's 4110206. Hence it's useful to be able to right-justify them. Dates aren't a great example (because good date/time libraries do exist), but they're more universally understood than domain-specific examples. I guess you can have 0 as Unix permissions, there might even be a 0 MAC address, but would you write them in decimal as (etc.) when all the other perms and addresses are written in oct or hex? addresses = [ 0x0014a466fba9, 0x0014a00b3fb1, , 0x003744a9012a, ] Right, so those aren't ideal examples either, because they're not decimal. Postcodes, or zip codes, also should be written as strings, even if they happen to be all digits. Hmm, maybe. I'm on the fence about that one. Of course, most of the time, I advocate a single multi-line text field Address, and let people key them in free-form. No postcode field whatsoever. I'm still looking for an example of where somebody would write the int zero in decimal using more than one 0-digit. While I'm sure they are fascinating in and of themselves, examples of numbers written as strings, in hex or octal, non-zero numbers written without leading zeroes, or zero written with only a single digit don't interest me :-) Frankly, I'm in broad agreement: using 000 to represent 0 isn't particularly useful, given that 0001 is an error. But since C-like languages (and Py2) use the leading zero to mean octal, and mathematics ignores the leading zero, there's no way to avoid confusing people other than by having an instant error. There's probably code out there that uses 000 to mean 0, but personally, I wouldn't be against deprecating it. One thing that's really REALLY annoying is running into something that uses virtually the same syntax to mean something almost, but not entirely, identical... and completely incompatible. If Py3 allowed 0009 to mean 9, we would have nightmares all over the place, even without Py2/Py3 conversion. Unadorned octal still shows up in one place in Py3, and that's string escapes: \33 '\x1b' b\33 b'\x1b' I hope this *never* gets changed to decimal or hex. If it's considered a problem, the only solution is to excise it altogether. Please do NOT do what BIND9 did, and have \033 mean 33 decimal... it bugged me no end when I tried to move some binary around between DNS and other systems... ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Wed, 22 Jul 2015 03:21 am, Antoon Pardon wrote: On 07/19/2015 07:39 AM, Steven D'Aprano wrote: In Python 2, integer literals with leading zeroes are treated as octal, so 09 is a syntax error and 010 is 8. This is confusing to those not raised on C-style octal literals, so in Python 3 leading zeroes are prohibited in int literals. Octal is instead written using the prefix 0o, similar to hex 0x and binary 0b. Consequently Python 3 makes both 09 and 010 a syntax error. However there is one exception: zero itself is allowed any number of leading zeroes, so 0 is a legal way to write zero as a base-10 int literal. Does anyone use that (mis)feature? Yes. I like to sometime write numbers with leading zeros. In Python 2, those numbers will be in octal: nums = [, 0001, 0002, 0003, 0004, 0005, 0006, 0007, # 0008 and 0009 are syntax errors 0010, ... ] In Python 3, using leading zeroes is always a syntax error, unless all the numbers are zero: # Okay nums = [, , , , ... ] # Fails nums = [, 0001, 0002, 0003, ...] I'm not interested in the Python 2 case with octal numbers. Can you show an example of how you would use this in Python 3? Or at least explain what benefit you get from typing out a block of all zeroes by hand, instead of (say) this? nums = [0]*10 Sometimes these numbers represent codeblocks of a fixed number of digits. Always writing those numbers with this number of digits helps being aware of this. It is also easier for when you need to know how many leading zero's such a number has. I'm not sure what you mean here. Python ints don't have a fixed number of digits. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Tuesday, July 21, 2015 at 11:07:43 AM UTC-7, Emile van Sebille wrote: On 7/21/2015 10:58 AM, sohcahto...@gmail.com wrote: IMO, leading zeroes just looks like visual noise, and if I wanted to align numbers, I'd just use spaces. Aligning numbers using spaces doesn't always align -- using zeros does. Emile You've got me confused. They should align just fine if you're using a fixed-width font. If you're not using a fixed-width font in your programming, then I don't know what to say to you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Tuesday, July 21, 2015 at 11:38:53 AM UTC-7, sohca...@gmail.com wrote: On Tuesday, July 21, 2015 at 11:07:43 AM UTC-7, Emile van Sebille wrote: On 7/21/2015 10:58 AM, sohcahto...@gmail.com wrote: IMO, leading zeroes just looks like visual noise, and if I wanted to align numbers, I'd just use spaces. Aligning numbers using spaces doesn't always align -- using zeros does. Emile You've got me confused. They should align just fine if you're using a fixed-width font. If you're not using a fixed-width font in your programming, then I don't know what to say to you. I should probably state that I may use leading zeroes when using hexadecimal numbers. For example, I might write 0x000ABCDE, rather than 0xABCDE, but that's only if I'm using a lot of 32-bit values. If I only care about a single byte, I will use 0x01, for example. But for base-10, I would never use leading zeroes. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
Don't be noob ? ;) Always remove leading zeroes ? One case that comes to mind is ASCII art like code... where programmer may want to align numbers for clearity: 0014324 0234545 345 0534543 ^ That could be a problem but possibly solveable with spaces instead: 14324 234545 345 534543 ^ Looks less good though in non-fixed-sized font. Bye, Skybuck. -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Sunday, July 19, 2015 at 3:19:01 AM UTC-5, Skybuck Flying wrote: 14324 234545 345 534543 ^ Looks less good though in non-fixed-sized font. The obvious solution is to use a fixed width font. If you're inserting syntactical noise simply to maintain readability in variable width fonts, then you may want to reconsider the practicality of such a font. Readability counts. And errors (even mental errors) should never pass silently. -- https://mail.python.org/mailman/listinfo/python-list
Integers with leading zeroes
In Python 2, integer literals with leading zeroes are treated as octal, so 09 is a syntax error and 010 is 8. This is confusing to those not raised on C-style octal literals, so in Python 3 leading zeroes are prohibited in int literals. Octal is instead written using the prefix 0o, similar to hex 0x and binary 0b. Consequently Python 3 makes both 09 and 010 a syntax error. However there is one exception: zero itself is allowed any number of leading zeroes, so 0 is a legal way to write zero as a base-10 int literal. Does anyone use that (mis)feature? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Integers with leading zeroes
On Sat, Jul 18, 2015 at 11:39 PM, Steven D'Aprano st...@pearwood.info wrote: In Python 2, integer literals with leading zeroes are treated as octal, so 09 is a syntax error and 010 is 8. This is confusing to those not raised on C-style octal literals, so in Python 3 leading zeroes are prohibited in int literals. Octal is instead written using the prefix 0o, similar to hex 0x and binary 0b. Consequently Python 3 makes both 09 and 010 a syntax error. However there is one exception: zero itself is allowed any number of leading zeroes, so 0 is a legal way to write zero as a base-10 int literal. It's obviously a base-8 literal, not a base-10 literal. :-P Does anyone use that (mis)feature? I don't, but why should it matter? -- https://mail.python.org/mailman/listinfo/python-list