Sep-20-2019, 06:34 PM
(This post was last modified: Sep-20-2019, 06:34 PM by newbieAuggie2019.)
(Sep-18-2019, 08:25 AM)wavic Wrote: I didn't change the links. :)Oh, dear! I must have gone completely bonkers by now ...
(Sep-18-2019, 11:10 AM)wavic Wrote: Here it is. Windows 10 Command Prompt:Thanks again!
https://prnt.sc/p7pc9d
Finally, I managed to do it too!
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:
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:
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:
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
"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