[Python-Dev] str with base (original) (raw)
Gareth McCaughan gmccaughan at synaptics-uk.com
Thu Jan 19 11:23:30 CET 2006
- Previous message: [Python-Dev] str with base
- Next message: [Python-Dev] str with base
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wednesday 2006-01-18 16:55, Steven Bethard wrote:
[Raymond] > Perhaps introduce a single function, base(val, radix=10, > prefix=''), as a universal base converter that could replace > bin(), hex(), oct(), etc.
+1 on introducing base()
Introducing a new builtin with a name that's a common, short English word is a bit disagreeable. The other thing about the name "base" is that it's not entirely obvious which way it converts: do you say
base(123,5)
to get a string representing 123 in base 5, or
base("123",5)
to get the integer whose base 5 representation is "123"? Well, one option would be to have both of those work :-). (Some people may need to do some deep breathing while reciting the mantra "practicality beats purity" in order to contemplate that with equanimity.)
Alternatively, a name like "to_base" that clarifies the intent and is less likely to clash with variable names might be an improvement.
Or there's always %b, whether that ends up standing for "binary" or "base". Or %b for binary and %r for radix, not forgetting the modifiers to get numbers formatted as Roman numerals.
-- Gareth McCaughan
- Previous message: [Python-Dev] str with base
- Next message: [Python-Dev] str with base
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]