Popular recipes tagged "meta:requires=msvcrt"http://code.activestate.com/recipes/tags/meta:requires=msvcrt/2017-02-10T21:34:45-08:00ActiveState Code RecipesA simple text file pager in Python (Python) 2017-02-10T21:34:45-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580755-a-simple-text-file-pager-in-python/ <p style="color: grey"> Python recipe 580755 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/pagination/">pagination</a>, <a href="/recipes/tags/paging/">paging</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This recipe shows how to create a simple text file pager in Python. It allows you to view text content a page at a time (with a user-definable number of lines per page). Like standard Unix utilities, it can either take a text file name as a command-line argument, or can read the text from its standard input, which can be redirected to come from a file, or to come from a pipe. The recipe is for Windows only, though, since it uses the msvcrt.getch() function, which is Windows-specific. However, the recipe can be modified to work on Unix by using things like tty, curses, termios, cbreak, etc.</p> <p>More details here:</p> <p><a href="https://jugad2.blogspot.in/2017/02/tp-simple-text-pager-in-python.html" rel="nofollow">https://jugad2.blogspot.in/2017/02/tp-simple-text-pager-in-python.html</a></p> add password masking ability to getpass.getpass() (Python) 2016-01-13T00:46:40-08:00KingMakhttp://code.activestate.com/recipes/users/4193393/http://code.activestate.com/recipes/579148-add-password-masking-ability-to-getpassgetpass/ <p style="color: grey"> Python recipe 579148 by <a href="/recipes/users/4193393/">KingMak</a> (<a href="/recipes/tags/character/">character</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/getpass/">getpass</a>, <a href="/recipes/tags/hiding/">hiding</a>, <a href="/recipes/tags/masking/">masking</a>, <a href="/recipes/tags/msvcrt/">msvcrt</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>adding the ability to display a password masking character of the programmer's choice</p> getch()-like unbuffered character reading from stdin on both Windows and Unix (Python) 2015-08-19T04:45:51-07:00jwhite88http://code.activestate.com/recipes/users/4192711/http://code.activestate.com/recipes/579095-getch-like-unbuffered-character-reading-from-stdin/ <p style="color: grey"> Python recipe 579095 by <a href="/recipes/users/4192711/">jwhite88</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>A small utility class to read single characters from standard input, on both Windows and UNIX systems. It provides a getch() function-like instance.</p> <p>This extends the original script by adding a timeout necessary for another project.</p> The Easy Cow (Python) 2012-12-06T14:22:36-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578367-the-easy-cow/ <p style="color: grey"> Python recipe 578367 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>). </p> <p>If you thought the programs for <a href="http://code.activestate.com/recipes/578366/">recipe 578366</a> were too difficult to understand, you have just found an upgrade to the COW language: mnemonics humans can understand. This recipe makes a slight alteration to the interpreter so as to take the decoded instructions instead of the COW (moo) instructions.</p> The Normal Cow (Python) 2012-12-06T14:14:28-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578366-the-normal-cow/ <p style="color: grey"> Python recipe 578366 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>). </p> <p>Ever heard of an esoteric language named COW or wanted to run a program written with just the letters M and O? This recipe provides a COW interpreter that is able to run such programs and decodes them so that they are much easier to read for those who do not know the common bovine tongue.</p> EZ DDX COW (Python) 2012-12-07T02:21:51-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578373-ez-ddx-cow/ <p style="color: grey"> Python recipe 578373 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>). </p> <p>As with the original easy cow in <a href="http://code.activestate.com/recipes/578367/">recipe 578367</a>, a simple change to the original program allows for programming in a much more human-readable way. This recipe also allows for DDX programming and provides two more example COW programs below it as a demonstration of what may be done with the interesting language.</p> Command Line Windows Alarm Clock (Python) 2012-12-05T23:53:49-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578362-command-line-windows-alarm-clock/ <p style="color: grey"> Python recipe 578362 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/clock/">clock</a>, <a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>Using primitive but simple calculations, the alarm program below will find the offset to the time specified, sleep, and awake to run an alarm until terminated. This Windows recipe utilizes the <code>msvcrt</code> and <code>winsound</code> modules to operate and has limited use elsewhere.</p> COW with DDX (Python) 2012-12-07T02:17:19-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578372-cow-with-ddx/ <p style="color: grey"> Python recipe 578372 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>). </p> <p>Once you get bored with <a href="http://code.activestate.com/recipes/578366/">recipe 578366</a>, extending COW with DDX (Distributed Digestion eXtentions) provides a way to enhance program and replace instructions with more powerful options. This recipe provides a COW interpreter that utilities extra stomachs for the bovines to do their processing in.</p> Countdown Timer (Python) 2012-12-06T03:24:35-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578363-countdown-timer/ <p style="color: grey"> Python recipe 578363 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/sound/">sound</a>, <a href="/recipes/tags/timer/">timer</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>Ever wanted to set a timer that went off after a specified number of hours / minutes / seconds? This Windows recipe runs on the command line and does that with the arguments it accepts. Simple but effective, the program works well for remembering food in the oven among other things.</p> Ghoster - Windows program to create 0kb clone of folder or drive (Python) 2012-09-02T13:30:29-07:00commentator8http://code.activestate.com/recipes/users/4182761/http://code.activestate.com/recipes/578251-ghoster-windows-program-to-create-0kb-clone-of-fol/ <p style="color: grey"> Python recipe 578251 by <a href="/recipes/users/4182761/">commentator8</a> (<a href="/recipes/tags/clone/">clone</a>, <a href="/recipes/tags/copy/">copy</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>A program that will create a "ghost" of a given directory or drive on windows systems (easily adaptable to unix etc) to a given destination. This will consist of a copy of all folders and files with only names and extensions retained, not size. This allows browsing of a remote drive or network location when offline.</p> Get single keypress (Python) 2011-12-06T08:46:33-08:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577977-get-single-keypress/ <p style="color: grey"> Python recipe 577977 by <a href="/recipes/users/4172944/">Steven D'Aprano</a> (<a href="/recipes/tags/getch/">getch</a>, <a href="/recipes/tags/key/">key</a>). </p> <p>Here's a platform-independent module that exposes a single function, getch, which reads stdin for a single character. It uses msvcrt.getch on Windows, and should work on any platform that supports the tty and termios modules (e.g. Linux).</p> <p>This has been tested on Python 2.4, 2.5 and 2.6 on Linux.</p> Whitespace Interpreter (Python) 2010-05-24T12:02:11-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577110-whitespace-interpreter/ <p style="color: grey"> Python recipe 577110 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/interpreter/">interpreter</a>, <a href="/recipes/tags/whitespace/">whitespace</a>). Revision 2. </p> <p>Runs programs in "Programs" and creates *.WSO files when needed.</p> <p>Can be executed directly by double-click or on the command line.</p> <p>If run on command line, add "ASM" flag to dump program assembly.</p> Recursive file/folder cleaner (Python) 2011-02-12T20:30:59-08:00Alia Khourihttp://code.activestate.com/recipes/users/4169084/http://code.activestate.com/recipes/576643-recursive-filefolder-cleaner/ <p style="color: grey"> Python recipe 576643 by <a href="/recipes/users/4169084/">Alia Khouri</a> (<a href="/recipes/tags/cleaner/">cleaner</a>, <a href="/recipes/tags/cleaning/">cleaning</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/folder/">folder</a>, <a href="/recipes/tags/pyc/">pyc</a>, <a href="/recipes/tags/recursion/">recursion</a>, <a href="/recipes/tags/svn/">svn</a>). Revision 24. </p> <p>This script recursively scans a given path and applies a cleaning 'action' to matching files and folders. By default files and folders matching the specified (.endswith) patterns are deleted. Alternatively, _quoted_ glob patterns can used with the '-g' or '--glob' option.</p> <p>By design, the script lists targets and asks permission before applying cleaning actions. It should be easy to extend this script with further actions and also more intelligent pattern matching functions.</p> <p>The getch (single key confirmation) functionality comes courtesy of <a href="http://code.activestate.com/recipes/134892/" rel="nofollow">http://code.activestate.com/recipes/134892/</a></p> <p>To use it, place the script in your path and call it something like 'clean':</p> <pre class="prettyprint"><code>Usage: clean [options] patterns deletes files/folder patterns: clean .svn .pyc clean -p /tmp/folder .svn .csv .bzr .pyc clean -g "*.pyc" clean -ng "*.py" converts line endings from windows to unix: clean -e .py clean -e -p /tmp/folder .py Options: -h, --help show this help message and exit -p PATH, --path=PATH set path -n, --negated clean everything except specified patterns -e, --endings clean line endings -g, --glob clean with glob patterns -v, --verbose </code></pre> getch()-like unbuffered character reading from stdin on both Windows and Unix (Python) 2003-01-07T02:31:32-08:00Danny Yoohttp://code.activestate.com/recipes/users/98032/http://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/ <p style="color: grey"> Python recipe 134892 by <a href="/recipes/users/98032/">Danny Yoo</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 2. </p> <p>A small utility class to read single characters from standard input, on both Windows and UNIX systems. It provides a getch() function-like instance.</p> Egg Timer (Python) 2012-07-04T01:03:27-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/510390-egg-timer/ <p style="color: grey"> Python recipe 510390 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>This program can actually time anything you want, not just eggs. Unfortunately, it only runs on Windows.</p> Alarm Clock (Python) 2012-07-04T01:05:12-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/510387-alarm-clock/ <p style="color: grey"> Python recipe 510387 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/programs/">programs</a>). Revision 2. </p> <p>This program can act an an alarm clock on a Windows machine.</p> Module to allow Asynchronous subprocess use on Windows and Posix platforms (Python) 2006-12-01T17:30:02-08:00Josiah Carlsonhttp://code.activestate.com/recipes/users/1241800/http://code.activestate.com/recipes/440554-module-to-allow-asynchronous-subprocess-use-on-win/ <p style="color: grey"> Python recipe 440554 by <a href="/recipes/users/1241800/">Josiah Carlson</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 10. </p> <p>The 'subprocess' module in Python 2.4 has made creating and accessing subprocess streams in Python relatively convenient for all supported platforms, but what if you want to interact with the started subprocess? That is, what if you want to send a command, read the response, and send a new command based on that response?</p> <p>Now there is a solution. The included subprocess.Popen subclass adds three new commonly used methods: recv(maxsize=None), recv_err(maxsize=None), and send(input), along with a utility method: send_recv(input='', maxsize=None).</p> <p>recv() and recv_err() both read at most maxsize bytes from the started subprocess. send() sends strings to the started subprocess. send_recv() will send the provided input, and read up to maxsize bytes from both stdout and stderr.</p> <p>If any of the pipes are closed, the attributes for those pipes will be set to None, and the methods will return None.</p> <p>v. 1.3 fixed a few bugs relating to *nix support v. 1.4,5 fixed initialization on all platforms, a few bugs relating to Windows support, added two utility functions, and added an example of how to use this module. v. 1.6 fixed linux _recv() and test initialization thanks to Yuri Takhteyev at Stanford. v. 1.7 removed _setup() and __init__() and fixed subprocess unittests thanks to Antonio Valentino. Added 4th argument 'tr' to recv_some(), which is, approximately, the number of times it will attempt to recieve data. Added 5th argument 'stderr' to recv_some(), where when true, will recieve from stderr. Cleaned up some pipe closing. v. 1.8 Fixed missing self. parameter in non-windows _recv method thanks to comment. v. 1.9 Fixed fcntl calls for closed handles.</p> Progress Bar form WX in Child Thread of Main Python Code. (Python) 2006-04-14T09:30:59-07:00cheeng shu chinhttp://code.activestate.com/recipes/users/163970/http://code.activestate.com/recipes/491258-progress-bar-form-wx-in-child-thread-of-main-pytho/ <p style="color: grey"> Python recipe 491258 by <a href="/recipes/users/163970/">cheeng shu chin</a> (<a href="/recipes/tags/threads/">threads</a>). Revision 2. </p> <p>I come across some cases, where I need to hook a progress bar from WX to my current running python project/script to indicate the current process progress. Some how if you use MainLoop() in child thread will cause the WX session hang and EVT handle will failed. After some study, found that WXAPP class instance and MainLoop have to same namespace. I manage to redesign it and make it work now. Just mail/vote me, if you feel this is useful for your project. E-Mail : <a href="mailto:cheengshuchin@gmail.com">cheengshuchin@gmail.com</a></p> URL Refresher (Python) 2006-02-28T16:51:27-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/474101-url-refresher/ <p style="color: grey"> Python recipe 474101 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/programs/">programs</a>). </p> <p>This recipe will open a certain URL approximately every 0.5 second using your default browser. It continues to do so until a timeout occurs which has been specified (like the URL) by the user in number of minutes. The timeout starts a reminder that ends once the program has received input. The program then pauses until a key is struck or exits if ESC is pressed.</p> input_demo.py (Python) 2006-02-06T17:59:58-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/473854-input_demopy/ <p style="color: grey"> Python recipe 473854 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>This recipe demonstrates some keyboard input functions and screen output "magic" that some people may be interested (such as for an ASCII game). It is meant as a very simple demonstration only, and does not contain any error checking whatsoever. The style of the code is not the best, but it is meant to get a point across.&lt;br&gt;NOTE: This code was written to work in windows.</p>