Popular recipes tagged "meta:requires=re"http://code.activestate.com/recipes/tags/meta:requires=re/2016-09-22T12:25:30-07:00ActiveState Code RecipesSimple Matlab/Ocave like arrays conversion to numpy.arrays in python interpreter (Python) 2016-09-22T12:25:30-07:00Przemyslaw Podczasihttp://code.activestate.com/recipes/users/4179716/http://code.activestate.com/recipes/580700-simple-matlabocave-like-arrays-conversion-to-numpy/ <p style="color: grey"> Python recipe 580700 by <a href="/recipes/users/4179716/">Przemyslaw Podczasi</a> (<a href="/recipes/tags/array/">array</a>, <a href="/recipes/tags/interpreter/">interpreter</a>, <a href="/recipes/tags/matlab/">matlab</a>). </p> <p>Matlab/Octave syntax for 1D/2D arrays is more packed and doesn't require putting extra ',' and extra '[', ']' between dimensions. For this I wrote a parser that intercepts python interpreter and using numpy functionality parses Matlab's style arrays 1D and 2D into numpy.arrays.</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> Python script to find linux distros details from distrowatch (Python) 2015-07-29T18:24:23-07:00Emil george jameshttp://code.activestate.com/recipes/users/4191910/http://code.activestate.com/recipes/579038-python-script-to-find-linux-distros-details-from-d/ <p style="color: grey"> Python recipe 579038 by <a href="/recipes/users/4191910/">Emil george james</a> (<a href="/recipes/tags/beautifulsoup/">beautifulsoup</a>, <a href="/recipes/tags/internet/">internet</a>, <a href="/recipes/tags/module/">module</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/url/">url</a>, <a href="/recipes/tags/web/">web</a>). </p> <p>this script is a simlpe python script to find linux distros details from distrowatch using beautifulsoup,urllib2 modules.The script finds distros distribution details from <a href="http://distrowatch.com" rel="nofollow">distrowatch.com</a> when the distribution name is called as argument.</p> A Basic USe flag EDitor for Gentoo Linux supporting on-the-fly editing (Python) 2015-02-28T07:04:31-08:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/579028-a-basic-use-flag-editor-for-gentoo-linux-supportin/ <p style="color: grey"> Python recipe 579028 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/popen/">popen</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/user_input/">user_input</a>). </p> <p>This allows for on-the-fly editing. Simply drop abused.py into your path, and ensure that -a is not set in EMERGE_DEFAULT_OPTS in /etc/portage/make.conf. Then whenver you are installing new packages, use abused in place of emerge (eg: abused multitail) you will be presented with a list of use flags that are used in this action, and a prompt for editing any of them, simply hit enter with no changes to fire off the build.</p> Split file in place into two parts (Python) 2015-02-11T20:08:35-08:00shavy89http://code.activestate.com/recipes/users/4191634/http://code.activestate.com/recipes/579025-split-file-in-place-into-two-parts/ <p style="color: grey"> Python recipe 579025 by <a href="/recipes/users/4191634/">shavy89</a> (<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/splitting/">splitting</a>). Revision 2. </p> <p>Split file in place into two parts </p> Objectify of a XML node (Python) 2014-12-05T04:39:51-08:00Thomas Lehmannhttp://code.activestate.com/recipes/users/4174477/http://code.activestate.com/recipes/578976-objectify-of-a-xml-node/ <p style="color: grey"> Python recipe 578976 by <a href="/recipes/users/4174477/">Thomas Lehmann</a> (<a href="/recipes/tags/objectify/">objectify</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>The script allows you to convert a XML node into an object instance that has the XML node attributes as fields with the given values. The values are converted (when possible):</p> <ul> <li>from string to int</li> <li>from string to float</li> <li>or remain as string</li> </ul> <p>You also initially can provide a dictionary of (key,value) to ensure existence of certain fields which might not be provided by the XML node but on the other hand those values might be overwritten by the XML node.</p> <p>Please have a look at the docstring for the example ...</p> Python AsciiColor and video attributes (Python) 2014-07-24T04:25:53-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578908-python-asciicolor-and-video-attributes/ <p style="color: grey"> Python recipe 578908 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/dynamic_method/">dynamic_method</a>, <a href="/recipes/tags/metaprogramming/">metaprogramming</a>, <a href="/recipes/tags/python/">python</a>). Revision 5. </p> <p>This is a subclass of a standard str object that adds methods for applying color, and video attributes to text.</p> check_svn_number_for_all_modules (Python) 2014-04-14T07:41:43-07:00Shane Wanghttp://code.activestate.com/recipes/users/4171830/http://code.activestate.com/recipes/578861-check_svn_number_for_all_modules/ <p style="color: grey"> Python recipe 578861 by <a href="/recipes/users/4171830/">Shane Wang</a> . </p> <p>this tool is used to check whether an SVM number is included in current build or not. please note that this is only for internal use.</p> A Phone Book GUI Built in wxPython Connected To Database Using Data Grid View (Python) 2013-09-29T19:25:23-07:00toufic zaarourhttp://code.activestate.com/recipes/users/4187866/http://code.activestate.com/recipes/578676-a-phone-book-gui-built-in-wxpython-connected-to-da/ <p style="color: grey"> Python recipe 578676 by <a href="/recipes/users/4187866/">toufic zaarour</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/datagridview/">datagridview</a>, <a href="/recipes/tags/graphical/">graphical</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/interface/">interface</a>). </p> <p>this GUI as simple as it is explains some basic but important graphical database interfacing; "Add", "Edit","Delete","Search" and few others along with a data grid view. in order to work create an sqlite3 database as follows:</p> <p>data table : Phone, column 1 : ID, column 2 : name, column 3 : surname, column 4 : telephone.</p> <p>save the sqlite3 file as file.db in a folder called Data and place it in the same directory as your python script.</p> <p>if you want to create the sqlite3 database graphically use my previous post : <a href="http://code.activestate.com/recipes/578665-a-wxpython-gui-to-create-sqlite3-databases/" rel="nofollow">http://code.activestate.com/recipes/578665-a-wxpython-gui-to-create-sqlite3-databases/</a></p> <p>Also there is more: I did not use auto-number for 'id' because I also wanted to include in the code a renumbering script.</p> <p>I am pleased to receive all the suggestions and improvements on this site or to my e-mail directly if this is convenient to you.</p> <p>note: if you don't like the database table name, and columns name create your own but make sure to change them in the code as well! in the end life is great! remember that!</p> Recapitalize word in the beginning of every sentence (Python) 2014-01-05T14:11:00-08:00sky kokhttp://code.activestate.com/recipes/users/4188838/http://code.activestate.com/recipes/578796-recapitalize-word-in-the-beginning-of-every-senten/ <p style="color: grey"> Python recipe 578796 by <a href="/recipes/users/4188838/">sky kok</a> (<a href="/recipes/tags/regex/">regex</a>). Revision 2. </p> <p>Recapitalizes text, placing caps after end-of-sentence punctuation. Turning "hello world. how are you?" to "Hello world. How are you?"</p> Recursive Multimedia (audio, video) M3U Playlist Generator (Python) 2014-02-08T01:03:36-08:00Mano Bastardohttp://code.activestate.com/recipes/users/4182040/http://code.activestate.com/recipes/578771-recursive-multimedia-audio-video-m3u-playlist-gene/ <p style="color: grey"> Python recipe 578771 by <a href="/recipes/users/4182040/">Mano Bastardo</a> (<a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/ffmpeg/">ffmpeg</a>, <a href="/recipes/tags/generate/">generate</a>, <a href="/recipes/tags/m3u/">m3u</a>, <a href="/recipes/tags/mulitmedia/">mulitmedia</a>, <a href="/recipes/tags/os/">os</a>, <a href="/recipes/tags/playlist/">playlist</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/video/">video</a>). Revision 9. </p> <p>Generate an m3u playlist searching recursively for multimedia files (video or audio) in the given directory. Information from ID3 tags will be extracted for audio files with <a href="http://en.wikipedia.org/wiki/FFmpeg">FFmpeg</a> available.</p> An Entry with autocompletion for the Tkinter GUI (Python) 2012-09-06T19:16:09-07:00Miguel Ángel Alarcos Torrecillashttp://code.activestate.com/recipes/users/4183471/http://code.activestate.com/recipes/578253-an-entry-with-autocompletion-for-the-tkinter-gui/ <p style="color: grey"> Python recipe 578253 by <a href="/recipes/users/4183471/">Miguel Ángel Alarcos Torrecillas</a> (<a href="/recipes/tags/autocomplete/">autocomplete</a>, <a href="/recipes/tags/entry/">entry</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 2. </p> <p>An example of how to make an entry widget with autocompletion for the Tkinter GUI. It uses regular expression but you can subclass AutocompleteEntry and override the comparison method.</p> <p>You can use the arrow keys 'up' and 'down' to select an item at the listbox, and the 'right' key to take it to the entry widget.</p> mac address from ip address (Python) 2013-07-07T17:34:06-07:00judyhttp://code.activestate.com/recipes/users/4186659/http://code.activestate.com/recipes/578593-mac-address-from-ip-address/ <p style="color: grey"> Python recipe 578593 by <a href="/recipes/users/4186659/">judy</a> (<a href="/recipes/tags/address/">address</a>, <a href="/recipes/tags/adress/">adress</a>, <a href="/recipes/tags/ip/">ip</a>, <a href="/recipes/tags/mac/">mac</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>get the mac address from ip address work only in linux system</p> Get external IP (Text) 2013-07-01T05:52:39-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578584-get-external-ip/ <p style="color: grey"> Text recipe 578584 by <a href="/recipes/users/4184115/">greg zakharov</a> (<a href="/recipes/tags/ipv4/">ipv4</a>). Revision 2. </p> <p>In addition to the posts about IPv4. Examples on Python.</p> lndir.py (short python version of the BSD/X11 lndir utility) (Python) 2013-05-28T07:21:28-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578535-lndirpy-short-python-version-of-the-bsdx11-lndir-u/ <p style="color: grey"> Python recipe 578535 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/directories/">directories</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/os_walk/">os_walk</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/walk/">walk</a>). Revision 2. </p> <p>This should be valid for Python 2.6 and up, including the 3.x series.</p> car.py (Ctypes ARchiver in PYthon [libarchive ffi wrapper]) (Python) 2013-05-28T04:02:15-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578531-carpy-ctypes-archiver-in-python-libarchive-ffi-wra/ <p style="color: grey"> Python recipe 578531 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/bzip2/">bzip2</a>, <a href="/recipes/tags/cpio/">cpio</a>, <a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/ffi/">ffi</a>, <a href="/recipes/tags/gzip/">gzip</a>, <a href="/recipes/tags/lzma/">lzma</a>, <a href="/recipes/tags/pax/">pax</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tar/">tar</a>). Revision 3. </p> <p>CTypes libarchive wrapper, handles extraction only with no arguments.</p> slurp.py (Regex based simple parsing engine) (Python) 2013-05-26T18:00:58-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578532-slurppy-regex-based-simple-parsing-engine/ <p style="color: grey"> Python recipe 578532 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/parser/">parser</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/text_processing/">text_processing</a>). </p> <p>A parsing engine that allows you to define sets of patterns and callbacks, and process any I/O object in Pyton that has a readline() method.</p> System Authentication against /etc/shadow or /etc/passwd (Python) 2013-03-11T12:40:10-07:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/578489-system-authentication-against-etcshadow-or-etcpass/ <p style="color: grey"> Python recipe 578489 by <a href="/recipes/users/4167757/">James Mills</a> (<a href="/recipes/tags/authentication/">authentication</a>, <a href="/recipes/tags/password/">password</a>, <a href="/recipes/tags/system/">system</a>). </p> <p>Sometimes it's useful to perform System Authentication against a Local System using the /etc/shadow or /etc/passwd password databases. This recipe provides a simple function that does exactly that.</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>