Sep-21-2019, 03:37 PM
Hi!
This problem came up when I was searching for ways to colour and give styles to strings:
https://python-forum.io/Thread-colouring-strings?page=2
The f-string formatting seems to be the advisable choice since Python 3.6, so I want to be able to learn properly about them.
I want to compare different packages applying the same formatting (f-strings) to the same string with all the packages, to be fair in the comparison.
With all the other packages in the comparison group, I managed finally to make them work, but not with termcolor. Due to the way the attributes are applied, I cannot make it work with f-strings. It works if I don't use f-strings, but for the comparison, I'd really like to use them. Please, is there a way to do it?
This is the little program I use with the string to be formatted (I commented out the two lines that I tried with f-strings). The program works, but I wanted to apply f-strings to the coding. What am I doing wrong?:
Could you help me, please?
All the best,
This problem came up when I was searching for ways to colour and give styles to strings:
https://python-forum.io/Thread-colouring-strings?page=2
The f-string formatting seems to be the advisable choice since Python 3.6, so I want to be able to learn properly about them.
I want to compare different packages applying the same formatting (f-strings) to the same string with all the packages, to be fair in the comparison.
With all the other packages in the comparison group, I managed finally to make them work, but not with termcolor. Due to the way the attributes are applied, I cannot make it work with f-strings. It works if I don't use f-strings, but for the comparison, I'd really like to use them. Please, is there a way to do it?
This is the little program I use with the string to be formatted (I commented out the two lines that I tried with f-strings). The program works, but I wanted to apply f-strings to the coding. What am I doing wrong?:
# strings_compared_EXTRA_01.py # import sys from termcolor import colored, cprint # str1 = "dangerous", "RED", attrs=["bold", "underline"] # cprint(f'\nThis is {str1} ... for my mental health!\n\n') cprint('\nThis is ', end='') cprint('dangerous', 'green', attrs=['bold', 'underline'], end='') cprint('... for my mental health!', end='\n\n')It works, but I wanted to make it work with f-strings:
Could you help me, please?
All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs