Popular Python recipes tagged "meta:requires=os.path"http://code.activestate.com/recipes/langs/python/tags/meta:requires=os.path/2016-10-25T17:53:01-07:00ActiveState Code RecipesLines Of Code (LOC) (Python)
2016-10-25T17:53:01-07:00Jean Brouwershttp://code.activestate.com/recipes/users/2984142/http://code.activestate.com/recipes/580709-lines-of-code-loc/
<p style="color: grey">
Python
recipe 580709
by <a href="/recipes/users/2984142/">Jean Brouwers</a>
(<a href="/recipes/tags/count/">count</a>, <a href="/recipes/tags/lines/">lines</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/source/">source</a>).
Revision 3.
</p>
<p>Count the number of lines (code, comment, blank) in one or several Python source files.</p>
Quick-and-dirty Windows drive detector (Python)
2016-09-20T17:46:37-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580699-quick-and-dirty-windows-drive-detector/
<p style="color: grey">
Python
recipe 580699
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/drives/">drives</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/system_programming/">system_programming</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This is a quick-and-dirty Python script to detect the currently available drives on your Windows PC.</p>
A binary file split utility in Python (Python)
2016-04-07T18:19:35-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580637-a-binary-file-split-utility-in-python/
<p style="color: grey">
Python
recipe 580637
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple binary file split utility in Python.</p>
<p>It takes two command line arguments: 1) the name of the input file to split , 2) the number of bytes per file into which to split the input.</p>
File comparison utility in Python (Python)
2016-03-26T18:31:11-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580631-file-comparison-utility-in-python/
<p style="color: grey">
Python
recipe 580631
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>).
</p>
<p>This is a recipe to compare any two files via a Python command-line program.
It is like a basic version of the cmp command of Unix or the fc.exe (file compare) command of Windows.</p>
Use PyAudio to play a list of WAV files (Python)
2015-10-22T18:24:08-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579116-use-pyaudio-to-play-a-list-of-wav-files/
<p style="color: grey">
Python
recipe 579116
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/music/">music</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/sound/">sound</a>).
</p>
<p>This recipe shows how to use PyAudio, a 3rd-party Python audio toolkit, to play a list of WAV files on your computer. This is an enhanced version of a basic WAV code example on the PyAudio site. You can specify either one WAV filename on the command line, like this:</p>
<p>py pyaudio_play_wav.py chimes.wav</p>
<p>or specify a text file containing names of WAV files to play, like this:</p>
<p>py pyaudio_play_wav.py -f wav_fil_list.txt</p>
<p>The only dependency is PyAudio, which you can install with pip.</p>
Roll your own Postscript code from scratch (Python)
2015-12-09T23:30:13-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579136-roll-your-own-postscript-code-from-scratch/
<p style="color: grey">
Python
recipe 579136
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/ghostscript/">ghostscript</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/postscript/">postscript</a>, <a href="/recipes/tags/ps/">ps</a>).
</p>
<p>This recipe provides a mini-framework for creating custom Postscript PS and PDF files from scratch. It includes sample code for a personalized business index card.</p>
<p>Recipe does not use any Python PDF libraries. However, Ghostscript and a PDF viewer are useful for displaying/debugging output.</p>
<p>It's easier than you might think to roll your own Postscript code!</p>
Mandelbrot Set made simple (Python)
2015-12-28T17:56:08-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579143-mandelbrot-set-made-simple/
<p style="color: grey">
Python
recipe 579143
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/mandelbrot/">mandelbrot</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 2.
</p>
<p>This is a mini-framework for exploring the Mandelbrot Set.</p>
<p>It outputs to a Tkinter window or to a PNG file (Pillow package required). It includes a disk caching mechanism for saving and later retrieving Mandelbrot calculations to avoid recalculating the Set on each run.</p>
<p>See module documentation for further information. Compatible with Python 2 and 3.</p>
A UNIX-like "which" command for Python (Python)
2015-03-20T19:23:45-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579035-a-unix-like-which-command-for-python/
<p style="color: grey">
Python
recipe 579035
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/commands/">commands</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/which/">which</a>).
</p>
<p>UNIX users are familiar with the which command. Given an argument called name, it checks the system PATH environment variable, to see whether that name exists (as a file) in any of the directories specified in the PATH. (The directories in the PATH are colon-separated on UNIX and semicolon-separated on Windows.)</p>
<p>This recipe shows how to write a minimal which command in Python.
It has been tested on Windows.</p>
Monitor Progress of File Descriptors of Another Process (Python)
2014-05-30T01:10:53-07:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/578882-monitor-progress-of-file-descriptors-of-another-pr/
<p style="color: grey">
Python
recipe 578882
by <a href="/recipes/users/4182236/">Alfe</a>
(<a href="/recipes/tags/file_descriptor/">file_descriptor</a>, <a href="/recipes/tags/monitor/">monitor</a>, <a href="/recipes/tags/prediction/">prediction</a>, <a href="/recipes/tags/proc/">proc</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/progress/">progress</a>, <a href="/recipes/tags/watch/">watch</a>).
</p>
<p>This tool (inspired by azat@stackoverflow, see <a href="http://stackoverflow.com/a/16082562/1281485" rel="nofollow">http://stackoverflow.com/a/16082562/1281485</a>) allows to watch the progress of the file descriptors of another process. This can be used, for example, if you transfer a file to another host and the transferring program does not show any progress indication itself. Instead of waiting blindly until the routine is done, with this tool you can use Linux's proc file system to monitor the progress of the other process while it walks through the file.</p>
<p>The tool continuously monitors the position in and the size of the files the given process's file descriptors point to. For growing (or shrinking, but that's very unusual) files, a time when it was (or will be) empty is computed ("emptyTime"), for moving file descriptors (the typical case), the time when it started at position 0 ("startTime"), the time when it will reach the current size of the file ("reachTime") and when it will meet with the end of a growing (or shrinking) file is computed ("meetTime").</p>
<p>For fixed-size files the meetTime will be the same as the reachTime of course. The meetTime only makes sense in case a file is growing and at the same time read (e. g. when a movie is downloaded to a file by one process and converted by a different process; using this tool can tell you when the converter process might run dry on the input because the download wasn't fast enough, and in this case you maybe can pause the converter to prevent this situation).</p>
<p>The tool is designed as a library; the display of the information is independent from the gathering of the data. Please feel free to create more fancy displays, add percentage output etc.</p>
'Which' for Windows (Python)
2013-08-16T09:14:07-07:00Robert Pyronhttp://code.activestate.com/recipes/users/4174781/http://code.activestate.com/recipes/578642-which-for-windows/
<p style="color: grey">
Python
recipe 578642
by <a href="/recipes/users/4174781/">Robert Pyron</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/which/">which</a>, <a href="/recipes/tags/windows/">windows</a>).
Revision 2.
</p>
<p>WHICH.PY scans through all directories specified in the system %PATH%
environment variable, looking for the specified COMMAND(s). It tries
to follow the sometimes bizarre rules for Windows command lookup.</p>
download the Activestate cook book recipe (Python)
2013-01-29T16:24:22-08:00lwz7512http://code.activestate.com/recipes/users/4185066/http://code.activestate.com/recipes/578439-download-the-activestate-cook-book-recipe/
<p style="color: grey">
Python
recipe 578439
by <a href="/recipes/users/4185066/">lwz7512</a>
.
</p>
<p>Small effort to store the python recipes to our local</p>
<p>similar effort by other people:
543267-i-will-download-all-of-the-recipes-from-the-python
535162-i-download-all-the-python-cookbook-recipes</p>
Python script to create a header for Python scripts (Python)
2011-10-02T15:45:11-07:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/577846-python-script-to-create-a-header-for-python-script/
<p style="color: grey">
Python
recipe 577846
by <a href="/recipes/users/4179007/">userend</a>
(<a href="/recipes/tags/2/">2</a>, <a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/vim/">vim</a>).
Revision 5.
</p>
<p>This will create a header for a Python script. It is a nice way keep a track of what your script does and when it was created, the author of the script, etc.. </p>
<p>Update: Now, it will automatically open with one of the two most popular editors, Vim or Emacs! This script has been updated from the second version to replace spaces with underscores in the title, to convert uppercase to lowercase. It also checks to see if there is a script with the same name in the current working directory so it will not overwrite another file. Please leave comments and suggestions.</p>
gprof2dot.py (Python)
2012-05-18T14:34:13-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578138-gprof2dotpy/
<p style="color: grey">
Python
recipe 578138
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/profiling/">profiling</a>, <a href="/recipes/tags/tools/">tools</a>, <a href="/recipes/tags/visualization/">visualization</a>).
</p>
<p>This is the <code>gprof2dot.py</code> program converted for use with the latest version of Python (3.2). It generates a dot graph from the output of several profilers. Please observe the original License embedded by the author, Jose Fonseca. His website for this program can be found on <a href="http://code.google.com/p/jrfonseca/wiki/Gprof2Dot">Google Code</a>.</p>
CGI Image Viewer (Python)
2012-07-02T22:52:32-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578186-cgi-image-viewer/
<p style="color: grey">
Python
recipe 578186
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/old/">old</a>).
</p>
<p>If you have ever started a program and never finished it, then you may recognize the code below for what it is: an experiment begun but not completed, meant to allow viewing pictures on a server. It is included here as an exercise for the reader to complete and is committed for archival to be run under Python 2.5 or later versions.</p>
download the Activestate cook book recipe (Python)
2012-07-04T12:14:22-07:00Sudeep AMhttp://code.activestate.com/recipes/users/4182702/http://code.activestate.com/recipes/578193-download-the-activestate-cook-book-recipe/
<p style="color: grey">
Python
recipe 578193
by <a href="/recipes/users/4182702/">Sudeep AM</a>
.
Revision 2.
</p>
<p>Small effort to store the python recipes to our local</p>
<p>similar effort by other people:
543267-i-will-download-all-of-the-recipes-from-the-python
535162-i-download-all-the-python-cookbook-recipes</p>
Quickly add all dirs to sys.path if dir has .py file (Python)
2012-04-06T16:06:17-07:00Andrew Yurisichhttp://code.activestate.com/recipes/users/4180867/http://code.activestate.com/recipes/578097-quickly-add-all-dirs-to-syspath-if-dir-has-py-file/
<p style="color: grey">
Python
recipe 578097
by <a href="/recipes/users/4180867/">Andrew Yurisich</a>
(<a href="/recipes/tags/add/">add</a>, <a href="/recipes/tags/os_walk/">os_walk</a>, <a href="/recipes/tags/sys_path/">sys_path</a>).
Revision 2.
</p>
<p>Add all dirs under <code>folder</code> to sys.path if any .py files are found.
Use an abspath if you'd rather do it that way.</p>
<p>Uses the current working directory as the location of using.py.
Keep in mind that os.walk goes <em>all the way</em> down the directory tree.</p>
Password Card Generator (Python)
2012-01-26T02:37:30-08:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/578027-password-card-generator/
<p style="color: grey">
Python
recipe 578027
by <a href="/recipes/users/4179007/">userend</a>
(<a href="/recipes/tags/card/">card</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/passwd/">passwd</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/secret/">secret</a>).
</p>
<p>This project was inspired by the <a href="http://passwordcard.org" rel="nofollow">passwordcard.org</a> website. I wanted to see if I could do the same thing using Python. Select a password using this convenient card that you carry with you. </p>
Selective directory walking (Python)
2011-10-20T05:05:39-07:00Nick Coghlanhttp://code.activestate.com/recipes/users/2035254/http://code.activestate.com/recipes/577913-selective-directory-walking/
<p style="color: grey">
Python
recipe 577913
by <a href="/recipes/users/2035254/">Nick Coghlan</a>
(<a href="/recipes/tags/directories/">directories</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/globbing/">globbing</a>).
Revision 2.
</p>
<p>Python's os.walk() standard library iterator is useful if you want to walk an entire directory tree, but you're on your own when it comes to implementing name filtering and recursive depth limiting on top of it.</p>
<p>This recipe supports these features with an interface that is just as convenient as the underlying os.walk() API, while being significantly more powerful.</p>
Watch directory and do periodic commits to Subversion repository. (Python)
2011-02-10T14:00:13-08:00Jiri Zahradilhttp://code.activestate.com/recipes/users/4170037/http://code.activestate.com/recipes/577570-watch-directory-and-do-periodic-commits-to-subvers/
<p style="color: grey">
Python
recipe 577570
by <a href="/recipes/users/4170037/">Jiri Zahradil</a>
(<a href="/recipes/tags/subversion/">subversion</a>, <a href="/recipes/tags/watch/">watch</a>).
</p>
<p>You run this script with directory as parameter (defaults to current directory) and scripts watch this directory for changes in files - creating new file, deleting some file and modification to any file. All these changes are periodically commited to subversion repository using external commands.</p>
<p>Not especially good for coding but great for tracking changes in your text files f.e. during essay writing etc.</p>
Self Extracting Archiver (Python)
2012-06-20T22:32:01-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577485-self-extracting-archiver/
<p style="color: grey">
Python
recipe 577485
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/python/">python</a>).
Revision 6.
</p>
<p>This is a command-line tool for making self-extracting file archives in Python.</p>