https://snipboard.io/icvPrl.jpg All python developers will be using the console to print out messages or debug info at times in their development and some of these consoles can be running continuously, with many messages. Being able to format and color highlight these is a NICE way to improve our scripts and to highlight specific messages which is easily done with the "Rich" library. **Rich** allows you to use rich text formatting in the terminal and its super easy to use! ``` pip install rich ``` You can simply import the print function from the rich library and print will now be color syntax highlighting automatically for you with all its other features. It still uses the same inputs as the built in print, so its compatible with anything you already have written. ``` from rich import print ``` ### Color Syntax Highlighting If you then print an object or data element, rich colors things nicely for you.   ### Justification ``` from rich.console import Console console = Console(width=20) style = "bold white on blue" console.print("Rich", style=style) console.print("Rich", style=style, justify="left") console.print("Rich", style=style, justify="center") console.print("Rich", style=style, justify="right") This produces the following output: Rich Rich Rich Rich ``` ### Creating progress bars ``` from rich.progress import track for num in track(range(100)): print(num * 2) time.sleep(0.1) ``` More Examples:  ### Table Formatting This is a really powerful feature and hard to do with terminal output directly, so this is an impressive feature of rich. ``` from rich.table import Table from rich.console import Console table = Table("First table using rich!") table.add_column("Language", justify="right", style="bright_yellow", no_wrap=True) table.add_column("Year Initially Released", style="green") table.add_column("Most recent version", justify="right", style="red") table.add_row("", "Python", "1991", "3.9.1") table.add_row("", "R", "1993", "4.0.3") table.add_row("", "Java", "1995", "Java 15") console = Console() console.print(table) ```  What have you used Rich to do with your scripts? I hope you found some useful tips here and that you go try out rich with your python applications!
author | agileautomation | ||||||
---|---|---|---|---|---|---|---|
permlink | python-console-improvements-rich-library | ||||||
category | hive-129924 | ||||||
json_metadata | {"app":"peakd/2023.11.3","format":"markdown","tags":["python","learning","programming","development"],"users":[],"image":["https://snipboard.io/icvPrl.jpg","https://files.peakd.com/file/peakd-hive/agileautomation/23t76y5JTvs6tABdbEZHND7zRBgrQ5u9oKM3ppD7nLveSjxFha47rDRrmpRe1QfokeCwv.png","https://files.peakd.com/file/peakd-hive/agileautomation/23t793AB3gZRCv7izkQ2Q1pdeoA3UwH5n44whMLNFWCy2nM7roksiPJCJnrVn7bUukgsJ.png","https://files.peakd.com/file/peakd-hive/agileautomation/23sweNjTPhGbzoUHAWTUunhLG82Kt32AAuJf5ywERrHD9wbMRy2RJdWKhd1zy7Dqp3syy.png","https://files.peakd.com/file/peakd-hive/agileautomation/23t6vTKug2ZBPLmtsjAE8ziR4sEiMXdqmG8uZgtKaAti84dZWm3hys2gAjmR9krdfBHbL.png"]} | ||||||
created | 2024-01-16 15:40:00 | ||||||
last_update | 2024-01-16 15:40:00 | ||||||
depth | 0 | ||||||
children | 6 | ||||||
last_payout | 2024-01-23 15:40:00 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.144 HBD | ||||||
curator_payout_value | 0.144 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 2,869 | ||||||
author_reputation | 55,848,601,723 | ||||||
root_title | "Python - Console Improvements - Rich Library" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 130,528,724 | ||||||
net_rshares | 687,010,458,090 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
titusfrost | 0 | 28,832,643,168 | 100% | ||
unipsycho | 0 | 529,467,179 | 100% | ||
breezin | 0 | 6,979,771,426 | 100% | ||
bigtakosensei | 0 | 99,815,067,238 | 77% | ||
ganjafarmer | 0 | 283,545,537,180 | 100% | ||
joeyarnoldvn | 0 | 472,706,018 | 1.47% | ||
powpow420 | 0 | 1,447,209,087 | 50% | ||
stonergirls | 0 | 802,105,324 | 100% | ||
mytechtrail | 0 | 15,493,243,040 | 15% | ||
greenunion | 0 | 1,484,252,588 | 100% | ||
steinz | 0 | 629,016,606 | 50% | ||
teampdx | 0 | 796,725,850 | 100% | ||
teamoregon | 0 | 1,139,014,927 | 100% | ||
ganjafarmers | 0 | 902,982,881 | 100% | ||
vaporrhino | 0 | 2,037,557,330 | 100% | ||
zeusflatsak | 0 | 18,521,644,488 | 100% | ||
hivebuzz | 0 | 19,777,366,549 | 4% | ||
hive-169313 | 0 | 2,186,214,677 | 100% | ||
martial.media | 0 | 5,055,015,141 | 100% | ||
esecholito | 0 | 39,474,129,034 | 90% | ||
trezzahn | 0 | 29,881,880,698 | 100% | ||
woodathegsd | 0 | 15,457,749,937 | 100% | ||
caelum1infernum | 0 | 3,804,612,268 | 20% | ||
justmahi | 0 | 219,595,726 | 100% | ||
alessandrawhite | 0 | 47,026,950,494 | 100% | ||
bitterirony | 0 | 14,820,490,535 | 100% | ||
beckyonweb | 0 | 855,456,548 | 100% | ||
albro | 0 | 44,909,217,096 | 100% | ||
agileautomation | 0 | 112,835,057 | 100% |
Oh. I don't understand anything that you have said... Absolutely and 100% completely Klingon.. However this is interesting and I absolutely need as much help as I can possibly get in surviving learning about python. Hopefully I can trade you my secrets of Hive class and how to earn more here on the blockchain. Left alone the fact that you can work and code here on the blockchain and make good money as well... Oh I've got friends that have needs all the time. Sweet! Vote for you! Right on I'm excited to invest in you.
author | ganjafarmer |
---|---|
permlink | re-agileautomation-2024117t233819629z |
category | hive-129924 |
json_metadata | {"type":"comment","tags":["hive-129924","python","learning","programming","development"],"app":"ecency/3.0.44-mobile","format":"markdown+html"} |
created | 2024-01-18 07:38:21 |
last_update | 2024-01-18 07:38:21 |
depth | 1 |
children | 4 |
last_payout | 2024-01-25 07:38:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 533 |
author_reputation | 672,900,775,922,025 |
root_title | "Python - Console Improvements - Rich Library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 130,573,092 |
net_rshares | 94,974,877 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
agileautomation | 0 | 94,974,877 | 100% |
Thanks mate, I appreciate that and yes, I'd love to combine more crypto/blockchain with my programming skills!
author | agileautomation |
---|---|
permlink | re-ganjafarmer-s7g8de |
category | hive-129924 |
json_metadata | {"tags":["hive-129924"],"app":"peakd/2023.11.3"} |
created | 2024-01-18 08:46:27 |
last_update | 2024-01-18 08:46:27 |
depth | 2 |
children | 3 |
last_payout | 2024-01-25 08:46:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.012 HBD |
curator_payout_value | 0.011 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 110 |
author_reputation | 55,848,601,723 |
root_title | "Python - Console Improvements - Rich Library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 130,574,013 |
net_rshares | 59,124,582,193 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
ganjafarmer | 0 | 59,124,582,193 | 22% |
Come find me in the free compliments discord. Would that work?
author | ganjafarmer |
---|---|
permlink | re-agileautomation-2024118t0495667z |
category | hive-129924 |
json_metadata | {"type":"comment","tags":["hive-129924"],"app":"ecency/3.0.44-mobile","format":"markdown+html"} |
created | 2024-01-18 08:49:06 |
last_update | 2024-01-18 08:49:06 |
depth | 3 |
children | 2 |
last_payout | 2024-01-25 08:49:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 62 |
author_reputation | 672,900,775,922,025 |
root_title | "Python - Console Improvements - Rich Library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 130,574,064 |
net_rshares | 121,806,494 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
agileautomation | 0 | 121,806,494 | 100% |
Congratulations @agileautomation! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s) <table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@agileautomation/posts.png?202401161911"></td><td>You published more than 10 posts.<br>Your next target is to reach 20 posts.</td></tr> </table> <sub>_You can view your badges on [your board](https://hivebuzz.me/@agileautomation) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub> <sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub> To support your work, I also upvoted your post! **Check out our last posts:** <table><tr><td><a href="/hive-122221/@hivebuzz/lpud-202401"><img src="https://images.hive.blog/64x128/https://i.imgur.com/pVZi2Md.png"></a></td><td><a href="/hive-122221/@hivebuzz/lpud-202401">LEO Power Up Day - January 15, 2024</a></td></tr></table>
author | hivebuzz |
---|---|
permlink | notify-agileautomation-20240116t192925 |
category | hive-129924 |
json_metadata | {"image":["http://hivebuzz.me/notify.t6.png"]} |
created | 2024-01-16 19:29:24 |
last_update | 2024-01-16 19:29:24 |
depth | 1 |
children | 0 |
last_payout | 2024-01-23 19:29:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 970 |
author_reputation | 370,792,828,599,978 |
root_title | "Python - Console Improvements - Rich Library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 130,533,881 |
net_rshares | 122,932,118 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
agileautomation | 0 | 122,932,118 | 100% |