Skip to main content

oo view of file paths and names, subclassed from 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:

>>> 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 str/unicode, it can still be passed to other functions that expect a str/unicode object and work seamlessly.

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

Project details


Download files

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

Source Distributions

antipathy-0.73.003.zip (8.7 kB view details)

Uploaded Source

antipathy-0.73.003.tar.gz (7.7 kB view details)

Uploaded Source

File details

Details for the file antipathy-0.73.003.zip.

File metadata

  • Download URL: antipathy-0.73.003.zip
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for antipathy-0.73.003.zip
Algorithm Hash digest
SHA256 9186b6cfc99a828a9c283bcd2b2a3cf2db4e954f4a452df9916916e7bbdcf193
MD5 0d143e6c7b2f78d1ad188c7151ef0e9b
BLAKE2b-256 964e2aa6d2cc44f5732397cd07c990b819d306d3f127d849b247e597f9580eec

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for antipathy-0.73.003.tar.gz
Algorithm Hash digest
SHA256 d154fcd27de945df5f9a0b6d4ab9d42a676fca6d434a467ade2802e71fb0bc72
MD5 37bb5d4788e4bf83e6d22b6114817f88
BLAKE2b-256 670acdbb0fbd94e458ac5ab07e58be0d31d7b06c06189ca1f23292a1921dbcd0

See more details on using hashes here.

Supported by

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