list indices must be integers or slices, not str

Martin Di Paola martinp.dipaola at gmail.com
Wed Jul 20 14:59:19 EDT 2022


offtopic

If you want a pure-python but definitely a more hacky implementation,
you can play around with inspect.stack() and get the variables from
the outer frames.


# code:
x = 32
y = 42
printf("Hello x={x}, y={y}", x=27)

# output:
Hello x=27, y=42


The implementation of printf() was never released in PyPI (I guess I never saw
it as more than a challenge).

But the implementation is quite simple (I did a post about it):
https://book-of-gehn.github.io/articles/2021/07/11/Home-Made-Python-F-String.html

Thanks,
Martin.
On Wed, Jul 20, 2022 at 10:46:35AM -0600, Mats Wichmann wrote:
>On 7/20/22 05:04, Frank Millman wrote:
>
>> I think the preferred style these days is f'{x[-1]}' which works."
>>
>> Unfortunately the 'f' option does not work for me in this case, as I am
>> using a string object, not a string literal.
>
>For that you could consider
>
>https://pypi.org/project/f-yeah/
>
>(straying a bit off thread subject by now, admittedly)
>-- 
>https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list