{"id":14028,"date":"2020-09-09T15:32:31","date_gmt":"2020-09-09T15:32:31","guid":{"rendered":"https:\/\/holypython.com\/?p=14028"},"modified":"2021-03-28T00:43:53","modified_gmt":"2021-03-28T00:43:53","slug":"creating-a-speed-reader-with-python","status":"publish","type":"post","link":"https:\/\/holypython.com\/creating-a-speed-reader-with-python\/","title":{"rendered":"Creating a Speed Reader with Python"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"14028\" class=\"elementor elementor-14028\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-07722f8 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"07722f8\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7d1241c\" data-id=\"7d1241c\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1feb42c elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"1feb42c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Python Speed Reader Implementation (<i>4 steps<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cce01ad elementor-widget elementor-widget-text-editor\" data-id=\"cce01ad\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>When you become an engineer, and I mean not just by studying it in college but by experiencing it through daily life, inventions, nature and science fewer and fewer things will faze you.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-58f764d elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"58f764d\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-30bd415\" data-id=\"30bd415\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-35d8d0b elementor-widget elementor-widget-text-editor\" data-id=\"35d8d0b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>It&#8217;s also similar to what Elon Musk quoted the other day:<\/p><blockquote><p>\u201cAll of physics is either impossible or trivial. It is impossible until you understand it, and then it becomes trivial.\u201d E Rutherford<\/p><\/blockquote>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-4d9faa5 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"4d9faa5\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-dd2fe0c\" data-id=\"dd2fe0c\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-bccabc5 elementor-widget elementor-widget-text-editor\" data-id=\"bccabc5\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>So here is a very simple Python script that gives an idea about how all those professional speed reading software out there might be created.<\/p><p>It may be interesting for someone who is keen on speed reading or improving reading as a skill. Some people also like to ponder what they read.<\/p><p>I see benefit in both styles although I lean to the latter most of the time.<\/p><p>Even if you&#8217;re not after speed reading this is a great demonstration to expand a beginner Python programmer&#8217;s horizons about how real life applications and software can depend on a tiny simple script that you are also capable of creating.<\/p><p>We can achieve this Python script in 3 simple steps:<\/p><ol><li><b>importing libraries<\/b>: <code>win32com.client<\/code> module will be useful to create a connection to Notepad App in Windows and then send keys to it.<\/li><li><code><b>win32com.client<\/b><\/code>\u00a0: We&#8217;ll use <code>.Dispatch<\/code> method to create a connection to Windows COM interface.Then we&#8217;ll use 2 methods with the shell we&#8217;re creating:<ul><li><code>.Run:<\/code>\u00a0to run Notepad<\/li><li><code>.AppActivate:<\/code>\u00a0to make sure Notepad is the active window while sending keyboard keys.<\/li><\/ul><\/li><li><b>message<\/b><strong>: <\/strong>Just any message will do, this is what will be written at a predefined pace on your screen. So, ideally something you&#8217;d like to read.<\/li><li><b>loop<\/b><strong>: <\/strong>This is likely the most interesting part from the programming sense. We&#8217;ll create a loop that loops through the message and sends each character with a predefined delay. By adjusting this delay variable you can make the text or script appear slower or faster to your liking and needs.<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-01a2406 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"01a2406\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Python Tutorial (<i>via win32com.clent and time libraries<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6629946 elementor-widget elementor-widget-text-editor\" data-id=\"6629946\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>Step 1<\/b>: Importing libraries<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-71c633d elementor-widget elementor-widget-html\" data-id=\"71c633d\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import win32com.client\nimport time\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-704f786 elementor-widget elementor-widget-text-editor\" data-id=\"704f786\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>Step 2<\/b>: Initializing shell connection using <code>win32com.client.Dispatch(\"WScriptShell\")<\/code><\/p><p>We&#8217;re also using <code>.sleep() <\/code>method from <b>time <\/b>library to create a little bit of a delay so that input from Python isn&#8217;t too fast for Windows to execute in correct order.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d3b1fef elementor-widget elementor-widget-html\" data-id=\"d3b1fef\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>shell = win32com.client.Dispatch(\"WScript.Shell\")\nshell.Run(\"notepad\")\ntime.sleep(1)\nshell.AppActivate(\"Notepad\")\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d95934a elementor-widget elementor-widget-text-editor\" data-id=\"d95934a\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>Step 3<\/b>: This is straightforward. Just some nice message to read on the screen.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-470afcf elementor-widget elementor-widget-html\" data-id=\"470afcf\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>msg=\"\"\"Hello World \n\n\nelena@****.com\n12:50 PM : 10 minutes ago\nto me\n\nTo create is to recombine\u2019 said the molecular biologist Francois Jacob. Imagine if the man who\ninvented the railway and the man who invented the locomotive could never meet or speak to each other, \neven through third parties. Paper and the printing press, the internet and the mobile phone, \ncoal and turbines, copper and tin, the wheel and steel, software and hardware. I shall argue \nthat there was a point in human pre-history when big-brained, cultural, learning people for the \nfirst time began to exchange things with each other, and that once they started doing so, \nculture suddenly became cumulative, and the great headlong experiment of human economic \u2018progress\u2019 \nbegan. Exchange is to cultural evolution as sex is to biological evolution.\n\nFrom The Rational Optimist\nby Matt Ridley\n\"\"\"\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0170ef6 elementor-widget elementor-widget-text-editor\" data-id=\"0170ef6\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>Step 4<\/b>: Finally, the loop. It&#8217;s a simple loop that does two things:<\/p><ol><li>Create a time delay between sending each character.<\/li><li><code>.SendKeys()<\/code> method is used to send each character to Notepad as a key.<\/li><\/ol><div><p>delay here is expressed in seconds.<\/p><\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1ef8c73 elementor-widget elementor-widget-html\" data-id=\"1ef8c73\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>delay=0.04\nfor i in msg:\n    time.sleep(delay)\n    shell.SendKeys(i, 0)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-de3d0b4 elementor-widget elementor-widget-text-editor\" data-id=\"de3d0b4\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Additionally, you can also come up with a negatively correlated structure and call it pace. For example:<\/p><pre><code>pace =1\nif pace == 1:\n    delay = 1\nelif pace == 2:\n    delay = 0.5\nelif pace == 3:\n    delay = 0.025<\/code><\/pre><p>and so on. Something like that. This is what happens with consumer products. Since dealing with microseconds can be alienating to the general public. Parameters are usually prettified and made more presentable.<\/p><p>Let&#8217;s continue without the pace implementation though to keep things simple.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-48e42f2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"48e42f2\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-379eda8\" data-id=\"379eda8\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-5d6e071 elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"5d6e071\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Full Code (<i>Speed Reader Script Using Python to Send Keys<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cc54bee elementor-widget elementor-widget-text-editor\" data-id=\"cc54bee\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>So, here is the full code:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-311c1f3 elementor-widget elementor-widget-html\" data-id=\"311c1f3\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"Python\"><code>import time\nimport win32com.client\n\n###Shell Connection\nshell = win32com.client.Dispatch(\"WScript.Shell\")\nshell.Run(\"notepad\")\ntime.sleep(1)\nshell.AppActivate(\"Notepad\")\n\n###Message\nmsg=\"\"\"Hello World \n\n\nelena@****.com\n12:50 PM : 10 minutes ago\nto me\n\nTo create is to recombine\u2019 said the molecular biologist Francois Jacob. Imagine if the man who invented the railway and the man who invented the locomotive could never meet or speak to each other, even through third parties. Paper and the printing press, the internet and the mobile phone, coal and turbines, copper and tin, the wheel and steel, software and hardware. I shall argue that there was a point in human pre-history when big-brained, cultural, learning people for the first time began to exchange things with each other, and that once they started doing so, culture suddenly became cumulative, and the great headlong experiment of human economic \u2018progress\u2019 began. Exchange is to cultural evolution as sex is to biological evolution.\n\nFrom The Rational Optimist\nby Matt Ridley\n\"\"\"  \n\n###For Loop for sending characters in sequence with a delay\ndelay=0.04\nfor i in msg:\n    time.sleep(delay)\n    shell.SendKeys(i, 0)\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9f3c995 elementor-widget elementor-widget-text-editor\" data-id=\"9f3c995\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>And the result should be something like this:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d37cdc2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d37cdc2\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8bf9cff\" data-id=\"8bf9cff\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-dff2a8b elementor-widget elementor-widget-image\" data-id=\"dff2a8b\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"760\" height=\"410\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2020\/09\/speedreadingapp.gif\" class=\"attachment-large size-large wp-image-14031\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e477a9a elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"e477a9a\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Closing Thoughts (<i>Application Opportunities and Thank You<\/i>)<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f6e2702 elementor-widget elementor-widget-text-editor\" data-id=\"f6e2702\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Thank you for checking out this scripting tutorial with Python. If you&#8217;re like me you&#8217;re also going to enjoy how straightforward this little script is. It&#8217;s simple and plain-vanilla but it&#8217;s still quite impressive. I imagine this is something that&#8217;d be also useful for:<\/p><ul><li>Creating self-reminders<\/li><li>Training reading skills<\/li><li>Preparing demos, tutorials, blog content etc.<\/li><li>Living a James Bond fantasy (make sure the message destroys itself.)<\/li><li>Understanding software markets and commercial thinking<\/li><li>Packaging another program you&#8217;ve created.<\/li><li>Presentations.<\/li><li>Just practicing loops in Python<\/li><li>Jokes and pranks with your non-techy buddies.<\/li><\/ul><p>Please share with appropriate reference to HolyPython.com if you enjoyed this tutorial, so your community can also benefit from it.<\/p><p>Thanks for visiting.<\/p><p>Arrivederci!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Python Speed Reader Implementation (4 steps) When you become an engineer, and I mean not just by studying it in college but by experiencing it through daily life, inventions, nature and science fewer and fewer things will faze you. It&#8217;s also similar to what Elon Musk quoted the other day: \u201cAll of physics is either [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14031,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34,52,61],"tags":[],"class_list":["post-14028","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-intermediate","category-tutorials","category-scripting"],"acf":[],"_links":{"self":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts\/14028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/comments?post=14028"}],"version-history":[{"count":0,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts\/14028\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media\/14031"}],"wp:attachment":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media?parent=14028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/categories?post=14028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/tags?post=14028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}