Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
f-strings and termcolor
#3
(Sep-21-2019, 03:42 PM)ndc85430 Wrote: Well no, the commented out code doesn't make any sense, does it? str1 on line 7 is a tuple of three values and on line 8, that's used in the f-string, so you'll be printing that tuple. On line 11, the string that's displayed is 'dangerous' and the colour and other things are arguments to the function. Why would you think you'd put the arguments to the function inside the string you want to print (as you've done in line 7)?
Thank you for your time and answer!
Yes, I understand that, this was just one of my last attempts at it. I tried nesting inside {}, just beside dangerous (instead of {str1}), the characteristics {'RED'} and {attrs=['bold', 'underline']}, that is, trying to include everything in one-liner:
cprint(f'\nThis is  {dangerous, {'RED'}, {attrs=['bold', 'underline']}} ... for my mental health!\n\n')
I've tried with commas, without commas, with square brackets, without square brackets, with quotation marks, without quotation marks ... and of course, I've gotten all kinds of errors ...

I'm a newbie, and I find strange the way, on the line
cprint('dangerous', 'green', attrs=['bold', 'underline'], end='')
'green' is giving characteristics to 'dangerous' and followed by 'attrs' with an equal sign, with two more styles inside a pair of square brackets, and separated by a comma. I don't understand the logic in that process and how I can turn it into an f-string format.

As a last resort, I use the brute "trial and error method", that in some cases, provides me with the solution, and then it helps me, 'a posteriori', to understand the logic in it.
Cry

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
Reply


Messages In This Thread
f-strings and termcolor - by newbieAuggie2019 - Sep-21-2019, 03:37 PM
RE: f-strings and termcolor - by ndc85430 - Sep-21-2019, 03:42 PM
RE: f-strings and termcolor - by newbieAuggie2019 - Sep-21-2019, 04:34 PM
RE: f-strings and termcolor - by ThomasL - Sep-21-2019, 05:08 PM
RE: f-strings and termcolor - by newbieAuggie2019 - Sep-22-2019, 03:52 AM
RE: f-strings and termcolor - by snippsat - Sep-21-2019, 07:32 PM
RE: f-strings and termcolor - by santarosajoe - Jul-28-2020, 02:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 1,890 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 2,701 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Finding multiple strings between the two same strings Slither 1 3,345 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  colorama/termcolor not returning coloured lines kapilan15 3 8,556 Jan-14-2019, 12:57 PM
Last Post: buran
  lists, strings, and byte strings Skaperen 2 5,105 Mar-02-2018, 02:12 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020