Popular recipes tagged "path"http://code.activestate.com/recipes/tags/path/2013-09-23T06:44:23-07:00ActiveState Code RecipesInMemoryZip class (Python) 2013-09-23T06:44:23-07:00Thomas Lehmannhttp://code.activestate.com/recipes/users/4174477/http://code.activestate.com/recipes/578667-inmemoryzip-class/ <p style="color: grey"> Python recipe 578667 by <a href="/recipes/users/4174477/">Thomas Lehmann</a> (<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/zip/">zip</a>). </p> <p><strong>Why implementing this?</strong></p> <ul> <li>transfering a file or a folder (including sub folders) to another machine</li> <li>therefore zipping content to one compressed buffer</li> <li>keeping the relating ZIP in memory only but ...</li> <li>being able to save or load too</li> <li>and being able to unzip again at target destination</li> </ul> Dynamically create a dictionary of ascending paths (Python) 2012-12-03T22:50:47-08:00Scott S-Allenhttp://code.activestate.com/recipes/users/4181178/http://code.activestate.com/recipes/578354-dynamically-create-a-dictionary-of-ascending-paths/ <p style="color: grey"> Python recipe 578354 by <a href="/recipes/users/4181178/">Scott S-Allen</a> (<a href="/recipes/tags/bootstrap/">bootstrap</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/dynamic/">dynamic</a>, <a href="/recipes/tags/flexible/">flexible</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/portable/">portable</a>). </p> <p>Ripped from a more elaborate bootstrap script. A sequential set of parent-directories were required for environment variables and subsequent, portable. auto-discovery. </p> Find Path to Object (Python) 2012-02-05T07:07:33-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578033-find-path-to-object/ <p style="color: grey"> Python recipe 578033 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/search/">search</a>). </p> <p>After wondering what the easiest what to access one object from another was, the following functions were written to automatically discover the shortest path possible. The <code>find</code> function takes the item to find and the object to find it from and tries finding out the best access path. The optional arguments control the search depth, memory usage, et cetera. The <code>nth</code> function is a helper function for accessing data containers that cannot be indexed into. As a final note, line thirteen (<code>while candidates:</code>) will probably never evaluate to false.</p> Locate and import Python's standard regression tests (Python) 2010-09-17T11:31:31-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577394-locate-and-import-pythons-standard-regression-test/ <p style="color: grey"> Python recipe 577394 by <a href="/recipes/users/4172944/">Steven D'Aprano</a> (<a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/regression/">regression</a>, <a href="/recipes/tags/testing/">testing</a>). </p> <p>The Python standard library comes with an extensive set of regression tests. I had need to import and run some of these tests from my own code, but the test directory is not in Python's path. This simple helper function solves the problem.</p> Komodo JS Macro - insert a relative path from the current editor file (JavaScript) 2012-02-24T00:23:09-08:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577306-komodo-js-macro-insert-a-relative-path-from-the-cu/ <p style="color: grey"> JavaScript recipe 577306 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/relative/">relative</a>). Revision 3. </p> <p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can be used to generate a relative path from the current editor file location, which works great for HTML when linking to relative style sheets, images, etc...</p> <p>Upon execution of this macro, you will be prompted to browse and select the target file, then upon selecting the target path, the relative path location will be inserted into the editor at the current position.</p> <p>To best use this macro - assign a custom key-binding to the macro and then trigger the macro at will.</p> Relative path from one directory to another without explicit string functions (unix only) (Python) 2011-04-11T13:02:32-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/577356-relative-path-from-one-directory-to-another-withou/ <p style="color: grey"> Python recipe 577356 by <a href="/recipes/users/57155/">Denis Barmenkov</a> (<a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/relative/">relative</a>, <a href="/recipes/tags/unix/">unix</a>). Revision 4. </p> <p>I saw a <a href="http://code.activestate.com/recipes/208993/">recipe 208993</a> messed up with os.sep and '../' and decide to write near-pure-Python version. os.sep used in string expressions only for testing for root directory.</p> <p>Function deal with Unix paths (root: "/"), Windows systems are not supported (root: "C:\").</p> file path generator from path patterns (Python) 2010-07-09T19:10:59-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577230-file-path-generator-from-path-patterns/ <p style="color: grey"> Python recipe 577230 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/paths/">paths</a>, <a href="/recipes/tags/walk/">walk</a>). Revision 4. </p> <p>Provides a <code>_paths_from_path_patterns</code> that will generate a list of paths from a list of path patterns. A "path pattern" can include glob chars. By default it generates a recursive listing of file paths, but: recursion can be turned off, file and/or dir paths can be listed. It supports a list of glob exclusions or inclusions.</p> <p>This function makes it easy to implement typical "-r|--recursive" and "-x|--exclude" options for command-line scripts that work on given file paths. See <a href="#block-1">example usages below</a>.</p> <p>Note: I use a leading <code>_</code> on function names because my typical usage of my recipes is as re-usable <em>internal</em> functions in Python modules.</p> Adding the directory of the python executable to the system PATH under windows (Python) 2010-05-19T19:01:31-07:00Anthon van der Neuthttp://code.activestate.com/recipes/users/2403822/http://code.activestate.com/recipes/577233-adding-the-directory-of-the-python-executable-to-t/ <p style="color: grey"> Python recipe 577233 by <a href="/recipes/users/2403822/">Anthon van der Neut</a> (<a href="/recipes/tags/environment/">environment</a>, <a href="/recipes/tags/executable/">executable</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/variable/">variable</a>). </p> <p>If you install python under windows and then open a command shell (DOS-prompt, you normally get an error message if you type "python" at the prompt. This is because the directory of the python executable is not in the PATH environment variable. If you know where you installed python, you can add this via Control Panel -> System -> Advanced -> Environment Variables but this is not very user friendly way of doing things and error prone.</p> <p>This program, if run by double clicking the file or by dragging the file to a command shell, will add the directory of the executable associated with the .py extension to the PATH env. var (if it is not already in there). It will notify other programs of this change, but unfortunately <a href="http://command.com" rel="nofollow">command.com</a> is not smart enough to understand that. You have to open a new command shell after running the program in order to be able to run "python" at the dos prompt.</p> <p>If run with the optional command line parameter 'remove' the directory will be removed from the PATH.</p> Normalizing paths (Python) 2010-01-26T14:39:00-08:00Gustavo Nareahttp://code.activestate.com/recipes/users/4172869/http://code.activestate.com/recipes/577023-normalizing-paths/ <p style="color: grey"> Python recipe 577023 by <a href="/recipes/users/4172869/">Gustavo Narea</a> (<a href="/recipes/tags/absolute_path/">absolute_path</a>, <a href="/recipes/tags/normalization/">normalization</a>, <a href="/recipes/tags/normalize/">normalize</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/paths/">paths</a>). Revision 3. </p> <p>While dealing with paths, it's often necessary to make sure they all have the same structure so any operation you perform on them can be reliable, specially when it comes to comparing two or more paths. Unusual paths like "/this//is//a///path" or "another/path" can cause unexpected behavior in your application and this is where this function comes into play.</p> Path entire split & commonprefix (Python) 2011-04-06T20:29:46-07:00Maxime Fontenierhttp://code.activestate.com/recipes/users/4172150/http://code.activestate.com/recipes/577016-path-entire-split-commonprefix/ <p style="color: grey"> Python recipe 577016 by <a href="/recipes/users/4172150/">Maxime Fontenier</a> (<a href="/recipes/tags/commonprefix/">commonprefix</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/split/">split</a>). Revision 5. </p> <p>This recipe is a kind of extension to os.path It offers an entire split function and a true commonprefix for paths.</p> Prints full name of all occurrences of given filename in your PATH (Python) 2009-06-29T15:20:10-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/576823-prints-full-name-of-all-occurrences-of-given-filen/ <p style="color: grey"> Python recipe 576823 by <a href="/recipes/users/4170919/">Ben Hoyt</a> (<a href="/recipes/tags/filename/">filename</a>, <a href="/recipes/tags/find/">find</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/which/">which</a>). </p> <p>Simple program to print the full name of all occurrences of the given filename in your PATH. Kind of like the Unix "which" utility, but works for DLLs and other files as well.</p> <p>Usage: findinpath.py filename</p> Case insensitive filename on *nix systems - return the correct case filename (Python) 2008-11-25T16:27:13-08:00Campbell Bartonhttp://code.activestate.com/recipes/users/4168177/http://code.activestate.com/recipes/576571-case-insensitive-filename-on-nix-systems-return-th/ <p style="color: grey"> Python recipe 576571 by <a href="/recipes/users/4168177/">Campbell Barton</a> (<a href="/recipes/tags/case/">case</a>, <a href="/recipes/tags/case_insensitive/">case_insensitive</a>, <a href="/recipes/tags/convert/">convert</a>, <a href="/recipes/tags/filename/">filename</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/sensitive/">sensitive</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 9. </p> <p>When dealing with windows paths on a *nix system sometimes youll need to resolve case insensitive paths. While using a fat filesystem or making everything lowercase would work. this function means you can get python to take a case insensitive path and return the path with the correct case (if it exists).</p>