Giter Club home page Giter Club logo

mru's Introduction

Travis Coveralls Conda PyPI

MRU

Small Python module to manage Most Recently Used (MRU) file paths.

Say you want to remember the most recently used files so the user can quickly select one of these next time the application is launched. This module will manage that for you:

>>> from mru import MRU
>>> history = MRU(app='Economy App', org='Balliol College')
>>> history.add('~/Documents/Intro.pdf')
>>> pass  # ...later...
>>> history.add('~/Documents/The Wealth of Nations.pdf')
>>> history[0]
'~/Documents/The Wealth of Nations.pdf'

Entries are automatically saved to disk, so opening the application again works as aspected:

>>> from mru import MRU
>>> history = MRU(app='Economy App', org='Balliol College')
>>> list(history)
['~/Documents/The Wealth of Nations.pdf', '~/Documents/Intro.pdf']

MRU instances are iterables (collections.deque, more precisely). So you can iterate over the object directly, convert to lists etc. The most recent item comes first:

>>> for path in history:
...     print(path)
...
~/Documents/The Wealth of Nations.pdf
~/Documents/Intro.pdf

By default, the MRU module remembers up to 20 paths. Change this like this:

>>> history = MRU(app='Economy App', org='Balliol College', maxlen=10)

To remove all entries:

>>> history.clear()
>>> list(history)
[]

Where are the MRU entries saved? Depending on the platform, somewhere in the user's profile:

>>> history.file_path
'C:\\Users\\Adam Smith\\AppData\\Local\\Balliol College\\Economy App\\mru'

Assuming you're Adam Smith and you use Windows, that is!

MRU uses the AppDirs module to find a suitable location using user_config_dir(app, org). The organisation name is optional, but omitting it risks that the MRU will be saved in another application's configuration folder.

Licence

Distributed under the MIT licence.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.