Skip to main content

Alphabetize output filenames

Project description

aaaa

Build Status Coverage PyPI - Python Version PyPI - License

Have you ever been creating an animated plot by saving a series of images and joining them together? The obvious way to name these frames would be using numbers:

for i in range(15):
    plt.savefig('{}.png'.format(i))

But many operating systems will order these files as follows:

0.png
1.png
10.png
11.png
12.png
13.png
14.png
2.png
3.png
4.png
5.png
6.png
7.png
8.png
9.png

Thereby screwing up the order of your animation.

This is where aaaa (pronounced like a scream) comes in! aaaa has a single class which creates an iterator that yields an alphabetical sequence aa, ab, ac, etc. So we can change our above example:

from aaaa import aaaa

fname = aaaa()

for i in range(15):
    plt.savefig('{}.png'.format(next(fname)))

Which will preserve the order of the files in your operating system:

aa.png
ab.png
ac.png
ad.png
ae.png
af.png
ag.png
ah.png
ai.png
aj.png
ak.png
al.png
am.png
an.png
ao.png

File sorting can differ between operating systems, sometimes with serious results.

Installation

aaaa has no dependences and is tested on Python 3.5 through 3.8 and it can be installed via pip:

pip install aaaa

Usage

There are two ways to use aaaa. Firstly, you can loop directly over an aaaa instance, until there are no items left (in this case the last value of name will be zz):

from aaaa import aaaa

names = aaaa()

for name in names:
    print(name)

Or, you can use the next() operator to only get as many values as you need:

from aaaa import aaaa

names = aaaa()

for i in range(10):
    print(next(names))

The default length of an output from aaaa is 2 characters long - this will allow you to order 676 files. If you need a larger or smaller amount of characters you can specify this as an argument to aaaa:

from aaaa import aaaa

names_short = aaaa(1)
names_long = aaaa(4)

print(next(names_short), next(names_long))
# Outputs --> a aaaa

Beyond four or five characters in length, initializing aaaa becomes prohibitively slow. Note that four characters gives you 456976 permutations - so you should never need more than this.

Contribute

For my purposes this package is feature complete, but if you find a bug, or have a feature request, open an issue, or create a pull request!

License

The project is licensed under the MIT license.

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

aaaa-1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file aaaa-1.0-py3-none-any.whl.

File metadata

  • Download URL: aaaa-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.3

File hashes

Hashes for aaaa-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bf745b32ae110ad19addbfb11510cdce6b67a49db9843764d0a0e7bf32da2e1
MD5 938eb12111dda9baad34714af131dc6a
BLAKE2b-256 c4a387b5fddf2fa002916aadd82807841ed33a1ef7a2afe3e34935e35cbf7dc1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page