Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
colouring strings
#15
(Sep-18-2019, 08:25 AM)wavic Wrote: I didn't change the links. :)
Oh, dear! I must have gone completely bonkers by now ... Sad Big Grin Bonkself

(Sep-18-2019, 11:10 AM)wavic Wrote: Here it is. Windows 10 Command Prompt:

https://prnt.sc/p7pc9d
Thanks again!

Finally, I managed to do it too!
[Image: Finally-I-did-it-too.png]
By the way, I tried to use f-strings in the following little program (in the end, I commented those two lines out after so many trials and errors: invalid syntax, can't assign to literal ... ). 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 better:
[Image: dangerous.png]
I've been trying to work with more complex strings, like quotations:
# compare_complex_strings_04_for_cmder_FINAL.py
#

import sys
from termcolor import colored, cprint

name = "\u001b[33;1m\u001b[46;1m\u001b[1mAlbert Einstein\u001b[0m"
age = 76
quote1 = '\u001b[44;1m\u001b[1m\u001b[1m\u201cImagination is more important than knowledge.   \n\
Knowledge is limited.                            \n\
Imagination encircles the world.\u201d                \u001b[0m'
quote2 = '\u001b[44;1m\u001b[1m\u001b[1m\u201cTry not to become a man of success,             \n\
but rather try to become a man of value.\u201d        \u001b[0m'
quote3 = '\u001b[44;1m\u001b[1m\u001b[1m\u201cThe important thing is to not stop questioning. \n\
Curiosity has its own reason for existing.\u201d      \u001b[0m'


print("\n\n\u001b[4m\u001b[35;1mThis is printing strings with f-formatting:\u001b[0m")
print(f"""
{name} \u001b[32;1mwas a very famous scientist of the 20th century.
He was {age} when he died in 1955.

Many quotes have been attributed to him, for instance:\u001b[0m

{quote1}

\u001b[32;1mThis one also:\u001b[0m

{quote2}

\u001b[32;1mAnd even this one:\u001b[0m

{quote3}
""")
producing the following output:
[Image: complex-quotations-01.png]

Even with Chinese characters and the pronunciation indicated in pinyin:
# compare_complex_strings_03_for_cmder_FINAL.py
#


import timeit
import datetime
import sys
from termcolor import colored, cprint

name = "\u001b[33;1m\u001b[46;1m\u001b[1mJackie Chan\u001b[0m"
age = 65
famous_Chinese_proverb = "\u001b[44;1m\u001b[1m\u001b[1m\u201cA journey of a thousand miles begins with a single step.\u201d \n"
Chinese = "\u001b[44;1m\u001b[1m\u001b[1m(Chinese: 千里之行,始於足下).                             \u001b[0m\n\
                     "
pinyin = "\u001b[44;1m\u001b[1m\u001b[1m(pinyin: Qiānlǐ zhī xíng, shǐyú zú xià).                   \u001b[0m\n\
                                             "
literally = "\u001b[44;1m\u001b[1m\u001b[1m(literally: \u201cA journey of a thousand Chinese               \n\
miles (li) starts beneath one\'s feet\u201d).                    \u001b[0m\n"
birthday_str = '1954/04/07' # Birthday: 7 of April, 1954.
year, month, day = (int(x) for x in birthday_str.split('/'))
ans = datetime.date(year, month, day)
birthday = ans.strftime("%A %d of %B, %Y")

print("\n\n\u001b[4m\u001b[35;1mThis is printing strings with f-formatting:\u001b[0m")
print(f"""
\u001b[32;1mA famous Chinese proverb says:\u001b[0m\n\n\
{famous_Chinese_proverb}
{Chinese}
{pinyin}                  
{literally}\u001b[0m\n 

{name}\u001b[32;1m is a well-known Chinese actor.
Next year he is {age+1} years old.\n 
He was born on {birthday}.\u001b[0m
""")
producing the following output:
[Image: complex-quotations-02.png]
Well, I find it too bothersome for what I think it's not a complicated output, and the attribute of 'italic' seems to be impossible in a computer running on a Windows operating system.

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
colouring strings - by newbieAuggie2019 - Sep-17-2019, 03:06 AM
RE: colouring strings - by wavic - Sep-17-2019, 03:14 AM
RE: colouring strings - by newbieAuggie2019 - Sep-17-2019, 04:23 PM
RE: colouring strings - by snippsat - Sep-17-2019, 04:42 PM
RE: colouring strings - by newbieAuggie2019 - Sep-17-2019, 09:46 PM
RE: colouring strings - by newbieAuggie2019 - Sep-17-2019, 04:48 PM
RE: colouring strings - by snippsat - Sep-17-2019, 05:13 PM
RE: colouring strings - by newbieAuggie2019 - Sep-17-2019, 05:37 PM
RE: colouring strings - by snippsat - Sep-17-2019, 06:22 PM
RE: colouring strings - by wavic - Sep-17-2019, 08:50 PM
RE: colouring strings - by snippsat - Sep-17-2019, 10:11 PM
RE: colouring strings - by newbieAuggie2019 - Sep-20-2019, 07:27 AM
RE: colouring strings - by wavic - Sep-18-2019, 08:25 AM
RE: colouring strings - by wavic - Sep-18-2019, 11:10 AM
RE: colouring strings - by newbieAuggie2019 - Sep-20-2019, 06:34 PM
RE: colouring strings - by newbieAuggie2019 - Sep-22-2019, 07:12 AM
RE: colouring strings - by newbieAuggie2019 - Sep-22-2019, 09:07 AM
RE: colouring strings - by jquast - Oct-22-2019, 02:28 PM
RE: colouring strings - by newbieAuggie2019 - Oct-22-2019, 03:31 PM
RE: colouring strings - by newbieAuggie2019 - Sep-24-2019, 10:42 AM
RE: colouring strings - by wavic - Sep-24-2019, 01:28 PM
RE: colouring strings - by newbieAuggie2019 - Sep-30-2019, 08:20 PM
RE: colouring strings - by jquast - Oct-23-2019, 03:44 AM
RE: colouring strings - by newbieAuggie2019 - Oct-23-2019, 08:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 818 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,818 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Finding multiple strings between the two same strings Slither 1 2,548 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  lists, strings, and byte strings Skaperen 2 4,265 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