[issue33013] Underscore in str.format with x option

2018-03-06 Thread Cheryl Sabella

Cheryl Sabella  added the comment:

Thanks guys.

I really thought I tried '{0:_x}'.format(123456789), but I guess I hadn't.  
Good to know that using format(123456879, '_x) is better.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33013] Underscore in str.format with x option

2018-03-06 Thread Eric V. Smith

Eric V. Smith  added the comment:

The format specifier (here, 'x') always goes last.

>>> '{0:_x}'.format(123456789)
'75b_cd15'

See https://docs.python.org/3/library/string.html#formatstrings for the details.

Serhiy is correct that it's often easier to use format() instead of ''.format() 
for testing things like this.

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33013] Underscore in str.format with x option

2018-03-06 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

>>> format(123456789, '_x')
'75b_cd15'

--
nosy: +serhiy.storchaka
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33013] Underscore in str.format with x option

2018-03-06 Thread Cheryl Sabella

New submission from Cheryl Sabella :

>From the doc 
>(https://docs.python.org/3/library/string.html#format-specification-mini-language):

> The '_' option signals the use of an underscore for a thousands separator for 
> floating point presentation types and for integer presentation type 'd'. For 
> integer presentation types 'b', 'o', 'x', and 'X', underscores will be 
> inserted every 4 digits. For other presentation types, specifying this option 
> is an error.

>>> '{0:_}'.format(123456789)
'123_456_789'
>>> '{0:x}'.format(123456789)
'75bcd15'
>>> '{0:x_}'.format(123456789)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: Invalid format specifier

What am I doing wrong?  I read the doc as saying that using `type` of `x` would 
result in the `_` separator to be inserted every 4 characters, so I was 
expecting the output to be '75b_cd15'.

Thanks!

--
messages: 313330
nosy: csabella
priority: normal
severity: normal
status: open
title: Underscore in str.format with x option
type: behavior
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com