Skip to main content

oo view of file paths and names, subclassed from bytes/str/unicode

Project description

Tired of calling a function for every path manipulation you need to do?

Is:

>>> path, filename = os.path.split(some_name)
>>> basename, ext = os.path.splitext(filename)
>>> basename = basename + '_01'
>>> new_name = os.path.join(path, basename+ext)

wearing on your nerves?

In short, are you filled with antipathy [1] for os.path?

Then get antipathy and work with Path:

>>> from antipathy import Path
>>> some_name = Path('/home/ethan/source/my_file.txt')
>>> backups = Path('/home/ethan/backup/')
>>> print some_name.path
'/home/ethan/source/'
>>> print some_name.ext
'.txt'
>>> print some_name.exists()
True  # (well, if it happens to exist at this moment ;)
>>> backup = backups / some_name.filename + '_01' + some_name.ext
>>> print backup
'/home/ethan/backup/my_file_01.txt'
>>> some_name.copy(backup)

Because Path is a subclass of bytes/str/unicode, it can still be passed to other functions that expect a bytes/str/unicode object and work seamlessly [2].

[1] https://www.google.com/#q=antipathy

[2] in most cases – there are a few places that do a type check instead of an isinstance check.

Project details


Download files

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

Source Distribution

antipathy-0.83.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distributions

antipathy-0.83.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

antipathy-0.83.0-py2-none-any.whl (13.4 kB view details)

Uploaded Python 2

File details

Details for the file antipathy-0.83.0.tar.gz.

File metadata

  • Download URL: antipathy-0.83.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for antipathy-0.83.0.tar.gz
Algorithm Hash digest
SHA256 02961011b644e0016fe9ebde4389c8298b2f4600984af7face2b7a99b54be11c
MD5 6ed417e1d0ed87c6642b8e04978f5b05
BLAKE2b-256 706cb2384485ccb49f5a6aff4b320a730b3016af29034a3345df0f5e2cbaae8e

See more details on using hashes here.

File details

Details for the file antipathy-0.83.0-py3-none-any.whl.

File metadata

File hashes

Hashes for antipathy-0.83.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e8cbfa0290ee5e3f1b4304a867a7e6592e3dbfc718ebfbb93d97fb73ceb63e7
MD5 d72f0ca34308c8697d6eb3c700d5b570
BLAKE2b-256 9f8def992980a89da3f6c7f9a79c7ef6ce5737d5112824b57ffdb5e4a4a0e419

See more details on using hashes here.

File details

Details for the file antipathy-0.83.0-py2-none-any.whl.

File metadata

File hashes

Hashes for antipathy-0.83.0-py2-none-any.whl
Algorithm Hash digest
SHA256 1908f00552bac50b064653462276190282d40a2056b12b4698b0a5aa2f8a66b1
MD5 f8e62d07378b75c676a987ecbf460878
BLAKE2b-256 97d6683da59ca7033b19f2b3e2c182b1fe2ab7265cbc4ac61040acf1a8523753

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