27;.format(d))
print()
print('Using f-string:')
print(f'Email: {d:{{k}} {{v}}}')
print()
print('Using f-string:')
k=6
v=9
print(f'Email: {d:{{k}} {{v}}}')
The result is:
NameError: name 'k' is not defined
-
Lele,
I'm afraid I was unclear. The ... in the code snippet was intended
to imply that these lines were appended to the end of the original code,
where d was defined.
-Ken
On 05/14/2018 12:30 AM, Lele Gaifax wrote:
> Ken Kundert writes:
>
>> I tried adding k and v to th
braces
in the format_spec, and the implementation of f-strings should be
updated to be consistent with the syntax specification, and with the
format method.
-Ken
On 05/13/2018 07:08 PM, Terry Reedy wrote:
> On 5/13/2018 3:22 PM, Ken Kundert wrote:
>
> Please do not double post.
>
&g
I am seeing an unexpected difference between the behavior of the string
format method and f-strings in Python3.6.
Here is an example:
import sys, os
from inform import error, os_error
class mydict(dict):
def __format__(self, template):
print('Template:', template)
I am seeing an unexpected difference between the behavior of the string
format method and f-strings.
Here is an example:
import sys, os
from inform import error, os_error
class mydict(dict):
def __format__(self, template):
print('Template:', template)
Sure enough. There is it, right there in the documentation. I did not
read far enough.
My bad.
Thanks!
-Ken
--
https://mail.python.org/mailman/listinfo/python-list
I just encountered this:
>>> '{:0s}'.format('hello')
Traceback (most recent call last):
File "", line 1, in
ValueError: '=' alignment not allowed in string format specifier
The exception goes away if I do not specify a width of the string:
>>> '{:s}'.format('hello')
'hello'
My reading of the