Skip to main content

Module to handle automatic variable naming, multiple files and some file acrobatics in python

Project description

filemapper

https://img.shields.io/travis/daegontaven/filemapper/master.svg?maxAge=2592000?style=plastic https://img.shields.io/codecov/c/github/daegontaven/filemapper.svg?maxAge=2592000?style=plastic https://img.shields.io/pypi/v/filemapper.svg?maxAge=2592000?style=plastic

This module is designed to create variables for files that are to be accessed collectively. Since files tend to take up a lot of memory, it is not advised to use this module to keep multiple files in a directory open. The mapper works by creating variables with same file name and maps them(Do not confuse this for the built-in maps() function) to their file location. These variables can then be accessed like regular files using read(). All the functions defined here return a tuple of successfully processed files.

Compatability

Tested Combinations:
  • Windows 10/8/7
  • Most Linux Distros
  • Python (3.5,3.4,2.7)

Using this module in any combination other than those listed above may produce unexpected results.

Unfortunately this module is currently incompatable with OSX, so do not install it without proper undertsanding of the source code.

Installation

pip install filemapper

Usage

>>>import filemapper as fm
>>>help(fm) #This will display help for this module
Creating variables
>>>import filemapper as fm
>>>print fm.create('resources') #Creates variables for files within the folder resources
{'nouns.dat':u'resources\\nouns.dat','adjectives.dat':u'resources\\adjectives.dat'}
>>>f = open(fm.read('nouns.dat')) #Passed into read() before it can be used.
>>>for i in f:print i #Prints out the whole 'nouns.dat'
A-bomb
A-bombs
A-frame
[Trunctuated 90959 Lines]
zymurgy

Example Case

>>>f = fm.create('resources')
>>>new_f = [sub_f[0] for sub_f in f.items()]
>>>for i in new_f: #Only prints the content of files that start with 'a'
...    if i[0] == 'a':
...        for x in  open(i, 'r'):print x
[Stdout Ommitted due to large size]
Loading Files
>>>print fm.load('resources','w') #Omittiing the second argument will default to read only mode
('nouns.dat','adjectives.dat')
>>>for i in fm.read('nouns.dat'):print i
[Stdout Ommitted due to large size]
Closing Files
>>>fm.close('nouns.dat')
('adjectives.dat')
>>>fm.close() #Closes all the files

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
filemapper-0.1.3.zip (8.7 kB) Copy SHA256 hash SHA256 Source None Dec 20, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page