Popular Python recipes tagged "meta:requires=struct"http://code.activestate.com/recipes/langs/python/tags/meta:requires=struct/2017-07-22T15:52:01-07:00ActiveState Code RecipesDBF reader and writer -- selective fields and nullreplace (Python) 2016-09-18T20:39:20-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/580696-dbf-reader-and-writer-selective-fields-and-nullrep/ <p style="color: grey"> Python recipe 580696 by <a href="/recipes/users/4189558/">Tomas Nordin</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>This fork assumes a desire for limited selection of field names. With huge files this might be necessary on some machines.</p> <p>Also, assuming that the meaning of null in a dbf file means zero might be a mistake, so the fork adds an argument nullreplace as way to choose what to replace null with. Null is sometimes used to mean missing value. This change is decoupled from the selective names feature.</p> Examples for random float between 0 and 1 (Python) 2015-06-25T17:55:33-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/579072-examples-for-random-float-between-0-and-1/ <p style="color: grey"> Python recipe 579072 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/example/">example</a>, <a href="/recipes/tags/random/">random</a>). </p> <p>I was researching how floats are stored in a computer and was trying to think up a way to generate random values between 0 and 1. Python already provides an implementation allowing this already, and two of the functions below are directly inspired by that code, but the third is a slightly different way of doing the same thing. A similar version of this code has been used to implement similar functionality in C# at one time. Others might also find it useful if they want to create equivalent code in a separate language while having access to random bytes but not random floats. It should be noted that the various implementations get slower as you go down the list.</p> Drop a minimal, valid Windows executable file to disk, for testing (Python) 2015-03-03T10:47:32-08:00Simon Harrisonhttp://code.activestate.com/recipes/users/4191738/http://code.activestate.com/recipes/579029-drop-a-minimal-valid-windows-executable-file-to-di/ <p style="color: grey"> Python recipe 579029 by <a href="/recipes/users/4191738/">Simon Harrison</a> (<a href="/recipes/tags/executable/">executable</a>, <a href="/recipes/tags/pe/">pe</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 3. </p> <p>Sometimes I need to create a valid windows executable file from a Python script for the sake of running a test.</p> WebSocket interface (Python) 2012-11-25T16:52:21-08:00Nick Farohttp://code.activestate.com/recipes/users/4184363/http://code.activestate.com/recipes/578348-websocket-interface/ <p style="color: grey"> Python recipe 578348 by <a href="/recipes/users/4184363/">Nick Faro</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/socket/">socket</a>, <a href="/recipes/tags/websocket/">websocket</a>). Revision 2. </p> <p>This tries its best to be a replacement for the regular <code>socket</code> module.</p> <p>It supports only sending and receiving but should be useful enough.</p> <p>The only real difference should be that you can't specify the number of bytes is received, instead do</p> <pre class="prettyprint"><code>for message in socket.recv(): print(message) </code></pre> <p>Revision 2: Added proper message receiving. Previously it just requested a ton of data. Now it reads 2 bytes, determines the length, then requests that much.</p> Python reader + writer for spss sav files (Linux, Mac & Windows) (Python) 2013-02-20T22:07:27-08:00Albert-Jan Roskamhttp://code.activestate.com/recipes/users/4177640/http://code.activestate.com/recipes/577811-python-reader-writer-for-spss-sav-files-linux-mac-/ <p style="color: grey"> Python recipe 577811 by <a href="/recipes/users/4177640/">Albert-Jan Roskam</a> (<a href="/recipes/tags/reader/">reader</a>, <a href="/recipes/tags/sav/">sav</a>, <a href="/recipes/tags/spss/">spss</a>, <a href="/recipes/tags/writer/">writer</a>). Revision 12. </p> <p><strong>Python Program to READ &amp; WRITE Spss system files (.sav) (Linux,Mac or Windows)</strong></p> <ul> <li><em>Check <a href="https://pypi.python.org/pypi/savReaderWriter/" rel="nofollow">https://pypi.python.org/pypi/savReaderWriter/</a> for the latest version (including the libraries!)</em></li> <li>Requires libspssdio.so.1 (LINUX) or libspssdio.dylib (MAC) or spssio32.dll (WINDOWS) plus associated libaries, which can be freely downloaded from: <a href="https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%2520for%2520IBM%25C2%25AE%2520SPSS%25C2%25AE%2520Statistics?lang=en" rel="nofollow">https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%20for%20IBM%C2%AE%20SPSS%C2%AE%20Statistics?lang=en</a></li> <li>It is recommended to download the v21 I/O files (required for writing zlib (.zsav) compressed files)</li> <li>December 2012 (complete rewrite):</li> <li>Added support for slicing, indexing, array slicing + other special methods</li> <li>Added support for writing spss date fields</li> <li>Added support for almost all meta data (missing values, sets, roles, etc.)</li> <li>Added support for 64 bit Windows (tested with Win7) and other OSs (z/Linux, Solaris, HP Linux, IBM AIX (untested though)</li> <li>Added support for reading and writing zlib compressed (.zsav) files</li> <li>Removed pesky segfault error when freeing memory</li> <li>Removed errors related to encoding</li> <li>Changed some Reader defaults (verbose=False, returnHeader=False)</li> <li>Renamed SavDataDictionaryReader into SavHeaderReader</li> </ul> <p><strong>LINUX:</strong></p> <p><em>Installation (tested on Linux Ubuntu 10):</em></p> <ul> <li>additional packages/files needed are: intel-icc8-libs_8.0-1_i386.deb,libicu32_3.2-3_i386.deb, libstdc++5_3.3.6-20_i386.deb, libirc.so.</li> <li>Run the following commands in your terminal: sudo apt-get install intel-icc8-libs; sudo apt-get install libicu32; sudo apt-get install libstdc++5.</li> <li>Then convert libirc.a (static) to libirc.so (dynamic), save in same location as libspssdio.so.1: ar vx intel-icc8-libs_8.0-1_i386.deb; tar -xzvf data.tar.gz ./usr/lib/libirc.a; ar -x libirc.a.</li> </ul> <p><em>Calling the program:</em></p> <ul> <li>In the TERMINAL type: export LD_LIBRARY_PATH=/path/of/additional/sofiles; python /some/path/wrapperToProgram.py. You may also add ld_library_path to .bashrc</li> <li>The wrapper starts with "from SavReaderWriter import *", followed by e.g. stuff from the if __name__ == '__main__' section</li> </ul> <p><strong>MAC OS:</strong></p> <ul> <li>you must put all the dylib files that come with the IBM SPSS_Statistics_InputOutput_Modules_* package in the macos directory somewhere that OS X can find them</li> <li>one simple way to accomplish this is to copy them to /usr/lib</li> </ul> <p><strong>WINDOWS:</strong></p> <ul> <li>You can also find this dll in the installation directory of SPSS (although SPSS is _not_ needed!)</li> <li>The .dll should be saved in the same location as this program.</li> </ul> <p><strong>USAGE:</strong> See docstrings + __main__ section</p> STL Writer (Python) 2012-08-22T18:46:34-07:00Manfred Moitzihttp://code.activestate.com/recipes/users/4183316/http://code.activestate.com/recipes/578246-stl-writer/ <p style="color: grey"> Python recipe 578246 by <a href="/recipes/users/4183316/">Manfred Moitzi</a> (<a href="/recipes/tags/3d/">3d</a>). </p> <p>Export 3D objects, build of faces with 3 or 4 vertices, as ASCII or Binary STL (Standard Triangulation Language) file.</p> For AMIGA-Heads Only. Peeking A Memory Address On A Classic AMIGA, Inside Text Mode Python. (Python) 2012-07-03T17:00:20-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578189-for-amiga-heads-only-peeking-a-memory-address-on-a/ <p style="color: grey"> Python recipe 578189 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/peek/">peek</a>, <a href="/recipes/tags/peeking/">peeking</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>For AMIGA-Heads Only...</p> <p>This code is purely for a minimum of a stock Classic AMIGA A1200(HD), E-UAE, and WinUAE running AMIGA OS3.0x to 3.1x. It will NOT work on any other platform!</p> <p>(It MIGHT work on AMIGA OS3.5x and 3.9x with Python 2.4.6, but totally untested and I hold no responsibility for the outcome when trying it.)</p> <p>It is a DEMO to peek a byte inside _ANY_ memory address inside the standard CPU 68EC020 16MB boundary.</p> <p>I experimented with this several years ago and have decided to finally release it. I do await the flak!</p> <p>It works from Python Versions 1.4.0 to 2.0.1 for the classic AMIGA.</p> <p>Ensure that the T: Volume exists on the running machine.</p> <p>See inside the code and text below it also as to how it works...</p> <p>Bazza, G0LCU...</p> How to Mutate a Float (Python) 2012-05-14T16:49:13-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578132-how-to-mutate-a-float/ <p style="color: grey"> Python recipe 578132 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/experiment/">experiment</a>, <a href="/recipes/tags/float/">float</a>, <a href="/recipes/tags/structure/">structure</a>). </p> <p>This is just an experiment to test my mental understanding of Python. It should not be used in any code as is violates the design principle that floats are to be immutable. The code also abuses <code>ctypes</code> and an understanding of how <code>floats</code> are currently arranged in memory. <code>set_float</code> is not guaranteed to work properly on any system, and may fail to work in the future if the data's arrangement changes.</p> Self-contained TWL06 Dictionary Module (515 KB) (Python) 2011-08-10T20:32:03-07:00Michael Foglemanhttp://code.activestate.com/recipes/users/4171845/http://code.activestate.com/recipes/577835-self-contained-twl06-dictionary-module-515-kb/ <p style="color: grey"> Python recipe 577835 by <a href="/recipes/users/4171845/">Michael Fogleman</a> (<a href="/recipes/tags/dawg/">dawg</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/scrabble/">scrabble</a>, <a href="/recipes/tags/trie/">trie</a>, <a href="/recipes/tags/twl06/">twl06</a>, <a href="/recipes/tags/word/">word</a>). Revision 4. </p> <p>A convenient, self-contained, 515 KB Scrabble dictionary module, ideal for use in word games.</p> <p>Functionality:</p> <ul> <li>Check if a word is in the dictionary.</li> <li>Enumerate all words in the dictionary.</li> <li>Determine what letters may appear after a given prefix.</li> <li>Determine what words can be formed by anagramming a set of letters.</li> </ul> <p>Sample usage:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; import twl &gt;&gt;&gt; twl.check('dog') True &gt;&gt;&gt; twl.check('dgo') False &gt;&gt;&gt; words = set(twl.iterator()) &gt;&gt;&gt; len(words) 178691 &gt;&gt;&gt; twl.children('dude') ['$', 'd', 'e', 's'] &gt;&gt;&gt; list(twl.anagram('top')) ['op', 'opt', 'pot', 'to', 'top'] </code></pre> DistCC 'top' (Python) 2013-12-01T11:19:56-08:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/577933-distcc-top/ <p style="color: grey"> Python recipe 577933 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/curses/">curses</a>, <a href="/recipes/tags/distcc/">distcc</a>, <a href="/recipes/tags/distributed/">distributed</a>, <a href="/recipes/tags/monitor/">monitor</a>, <a href="/recipes/tags/pack/">pack</a>, <a href="/recipes/tags/struct/">struct</a>, <a href="/recipes/tags/top/">top</a>, <a href="/recipes/tags/unpack/">unpack</a>). Revision 3. </p> <p>A small recipe for a curses based, 'top'-like monitor for DistCC. I know there is already distccmon-text, but I don't like it, and much prefer this sytle of monitoring. Note that I don't keep hosts around in the list like distccmon-gui/gnome. The screen is drawn for exactly what is currently in state. The terminal size is respected at initialization time, however resize events aren't handled. There is color designation of job types.</p> Decoding Binary Files (Python) 2011-03-15T00:11:10-07:00Yony Kochinskihttp://code.activestate.com/recipes/users/4175703/http://code.activestate.com/recipes/577610-decoding-binary-files/ <p style="color: grey"> Python recipe 577610 by <a href="/recipes/users/4175703/">Yony Kochinski</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/decode/">decode</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/python/">python</a>). Revision 2. </p> <p>One way to read files that contain binary fields is to use the <code>struct</code> module. However, to do this properly one must learn struct's format characters, which may look especially cryptic when sprinkled around the code. So instead, I use a wrapper object that presents a simple interface as well as type names that are more inline with many <a href="http://en.wikipedia.org/wiki/Interface_description_language">IDLs</a>.</p> Python reader for spss sav files (Python) 2011-07-25T18:59:49-07:00Albert-Jan Roskamhttp://code.activestate.com/recipes/users/4177640/http://code.activestate.com/recipes/577650-python-reader-for-spss-sav-files/ <p style="color: grey"> Python recipe 577650 by <a href="/recipes/users/4177640/">Albert-Jan Roskam</a> (<a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/pasw/">pasw</a>, <a href="/recipes/tags/sav/">sav</a>, <a href="/recipes/tags/spss/">spss</a>, <a href="/recipes/tags/statistics/">statistics</a>). Revision 3. </p> <p><strong>Python Program to read Spss system files (.sav)</strong></p> <ul> <li><em>* version 2 (FASTER!) *</em></li> <li>Requires spssio32.dll, which can be freely downloaded from: <a href="https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%2520for%2520IBM%25C2%25AE%2520SPSS%25C2%25AE%2520Statistics?lang=en" rel="nofollow">https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%20for%20IBM%C2%AE%20SPSS%C2%AE%20Statistics?lang=en</a></li> <li>You can also find this dll in the installation directory of SPSS (although SPSS is _not_ needed!)</li> <li><p>The .dll should be saved in the same location as this program.</p></li> <li><p>Parameters: <em>savFileName</em>: the file name of the spss data file; <em>returnHeader</em>: Boolean that indicates whether the first record should be a list of variable names (default: True); <em>recodeSysmisTo</em>: indicates to which value missing values should be recoded (default: ""); <em>selectVars</em>: indicates which variables in the file should be selected.The variables should be specified as a list or a tuple of valid variable names. If None is specified, all variables in the file are used (default: None); <em>verbose</em>: Boolean that indicates whether information about the spss data file (e.g., number of cases, variable names, file size) should be printed on the screen (default: True). <br /> <em>rawMode</em>: Boolean that indicates whether values should get SPSS-style formatting,and whether date variables (if present) should be converted to ISO-dates. If True, the program does not format any values, which increases processing speed. (default: = False) <em>interfaceEncoding</em> Indicates the mode in which text communicated to or from the I/O Module will be. Valid values are 'UTF-8' or 'CODEPAGE' (default = 'CODEPAGE')</p></li> <li><p>Typical use: savFileName = "d:/someFile.sav" with SavReader(savFileName) as sav: header = sav.next() for line in sav: process(line)</p></li> <li><p>Note: --<em>New version</em>: If you downloaded this previously, use the current version as it is <strong>MUCH faster!!</strong> --this code currently only works on Windows (32 bits). I might make it work on Linux Ubuntu 10 at some point. --date fields in spss are represented as the number of seconds since the Gregorian calendar. The program converts these, wherever possible, to ISO-dates (yyyy-mm-dd).</p></li> </ul> <p>Any feedback is welcome! I'm still learning!</p> NBD server in python (Python) 2011-02-08T20:59:23-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/577569-nbd-server-in-python/ <p style="color: grey"> Python recipe 577569 by <a href="/recipes/users/4068698/">Dima Tisnek</a> (<a href="/recipes/tags/analyze/">analyze</a>, <a href="/recipes/tags/block/">block</a>, <a href="/recipes/tags/device/">device</a>, <a href="/recipes/tags/disk/">disk</a>, <a href="/recipes/tags/io/">io</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/nbd/">nbd</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Linux Network Block Device server in Python</p> <p>This is a simplified version based on Kragen Sitaker's <a href="http://lists.canonical.org/pipermail/kragen-hacks/2004-May/000397.html" rel="nofollow">http://lists.canonical.org/pipermail/kragen-hacks/2004-May/000397.html</a></p> <p>Close is never actually called, at least not on the same connection -- linux C nbd-client -d seems to stall, perhaps it tries to open another socket?</p> <p>This code doesn't check for error conditions, failed reads/writes, past end of disk, etc.</p> <p>It prints io requests, you can analyze filesystem and user program io patterns.</p> LoggingWebMonitor - a central logging server and monitor. (Python) 2010-02-02T01:56:42-08:00Gabriel Genellinahttp://code.activestate.com/recipes/users/924636/http://code.activestate.com/recipes/577025-loggingwebmonitor-a-central-logging-server-and-mon/ <p style="color: grey"> Python recipe 577025 by <a href="/recipes/users/924636/">Gabriel Genellina</a> (<a href="/recipes/tags/client_server/">client_server</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/distributed/">distributed</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/web/">web</a>). Revision 3. </p> <p>LoggingWebMonitor listens for log records sent from other processes running in the same box or network. Collects and saves them concurrently in a log file. Shows a summary web page with the latest N records received.</p> Size of Python objects (revised). (Python) 2017-07-22T15:52:01-07:00Jean Brouwershttp://code.activestate.com/recipes/users/2984142/http://code.activestate.com/recipes/546530-size-of-python-objects-revised/ <p style="color: grey"> Python recipe 546530 by <a href="/recipes/users/2984142/">Jean Brouwers</a> (<a href="/recipes/tags/getsizeof/">getsizeof</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/sizeof/">sizeof</a>). Revision 21. </p> <p>This recipe determines the size of Python objects in bytes and has been further enhanced to handle ints, namedtuples, arrays and NumPy types better. Functions <em>alen</em> and <em>itemsize</em> have been updated. Support for Python 2.5 and earlier and the tests/examples have been removed. See project <a href="https://github.com/pympler/pympler">Pympler</a> for unit tests.</p> <p>See also other, simpler recipes like this <a href="http://code.activestate.com/recipes/577504">Compute memory footprint of an object and its contents</a>.</p> IP and MAC addresses (Python) 2016-07-07T17:52:15-07:00Jean Brouwershttp://code.activestate.com/recipes/users/2984142/http://code.activestate.com/recipes/577191-ip-and-mac-addresses/ <p style="color: grey"> Python recipe 577191 by <a href="/recipes/users/2984142/">Jean Brouwers</a> (<a href="/recipes/tags/ios/">ios</a>, <a href="/recipes/tags/ip/">ip</a>, <a href="/recipes/tags/ipv4/">ipv4</a>, <a href="/recipes/tags/mac/">mac</a>, <a href="/recipes/tags/macos/">macos</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/python2_4/">python2_4</a>, <a href="/recipes/tags/python3_5/">python3_5</a>, <a href="/recipes/tags/uuid/">uuid</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 3. </p> <p>This module collects all IP and MAC addresses from several available sources on the underlying system. See the module documentation for more details, supported Python releases and platforms.</p> Pyscanlogger - Python Port scan detector (Python) 2010-03-17T07:27:15-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576690-pyscanlogger-python-port-scan-detector/ <p style="color: grey"> Python recipe 576690 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/programs/">programs</a>, <a href="/recipes/tags/security/">security</a>). Revision 5. </p> <p>A pure Python program to detect network port scanning attacks. Currently logs different TCP port scans. Can run in the background like a daemon and log attacks to a log file.</p> socket.recv -- three ways to turn it into recvall (Python) 2005-04-05T13:47:57-07:00John Nielsenhttp://code.activestate.com/recipes/users/135654/http://code.activestate.com/recipes/408859-socketrecv-three-ways-to-turn-it-into-recvall/ <p style="color: grey"> Python recipe 408859 by <a href="/recipes/users/135654/">John Nielsen</a> (<a href="/recipes/tags/network/">network</a>). Revision 5. </p> <p>An issue with socket.recv is how to know when you are done receiving data. A TCP stream guarantees the bytes will not arrive out of order or be sent more than once. But you do not know the size of the data that will be sent to you. 100 bytes could be sent as group of 10 bytes or maybe in one shot. Ultimately, this means you have to use a loop in some fashion until you know it is done.</p> <p>The basic recv returns an empty string when the socket is disconnected. From that you can build a simple loop that will work as long as the sender manages to disconnect the socket at the appropriate time. However, there could be situations where a local error will mask as a clean shutdown or maybe a close() is never called.</p> <p>Three very basic methods are shown below that try to fix that problem. They use either a time-based, end marker, or size of payload method. Since you cannot be sure just what you are going to receive, you have to be careful that you get enough of a message to determine the size of payload or end marker.</p> <p>I updated the recv_size method to allocate data in larger chunks if it gets a large stream of data, which can increase performance.</p> Rename MP3 files from ID3 tags (does not require external ID3 modules) (Python) 2011-11-05T15:27:32-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/576811-rename-mp3-files-from-id3-tags-does-not-require-ex/ <p style="color: grey"> Python recipe 576811 by <a href="/recipes/users/4170754/">ccpizza</a> (<a href="/recipes/tags/id3/">id3</a>, <a href="/recipes/tags/mp3/">mp3</a>, <a href="/recipes/tags/rename/">rename</a>). Revision 5. </p> <p>Rename MP3 files in the current folder according to ID3 tags. This is based on Ned Batchelder's id3reader class. I only added the code in the <code>__main__</code> method.</p> <ul> <li>When run without arguments, the script renames the files in the current folder. The directory can be specified explicitly as the first argument.</li> <li>The files do not need to necessarily have the <code>MP3</code> extension.</li> <li>To move the files to directories based on album name use the <code>-d</code> switch.</li> <li>Does not work with other file types, such as OGG, M4A, MP4, etc.</li> <li>This is a quick and dirty script that works for me most of the times. If you need more power, try mutagen, picard, mp3tag or something similar.</li> </ul> Interrogating linux /dev/usb/hiddev0 in python (Python) 2009-07-07T01:32:17-07:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/576834-interrogating-linux-devusbhiddev0-in-python/ <p style="color: grey"> Python recipe 576834 by <a href="/recipes/users/4068698/">Dima Tisnek</a> (<a href="/recipes/tags/hid/">hid</a>, <a href="/recipes/tags/hiddev/">hiddev</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/usb/">usb</a>). </p> <p>What this recipe does:</p> <p>Maps linux usb hid ioctls and related C structs to python; Call ioctls, make some sense of output. Prints all reports for the device with some info.</p> <p>Works with python 2.4 (tested python 2.4.6 on linux amd64). Would need changes (e.g. print) for python 3.0. Might need changes (ioctl signed/unsigned "FIX") for newer python than tested.</p>