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.000.zip (8.7 kB view details)

Uploaded Source

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

Uploaded Source

File details

Details for the file antipathy-0.73.000.zip.

File metadata

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

File hashes

Hashes for antipathy-0.73.000.zip
Algorithm Hash digest
SHA256 daef45fbb97b6e0541e663215225f0a587ba716be1df9920b06db1fb6e2265c9
MD5 f45496671dec93e94e08021a8e80d95c
BLAKE2b-256 5c16f3ca67fa77b900559fc0403c3daa78a729c6c144d6023b128e7445e0b6bb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for antipathy-0.73.000.tar.gz
Algorithm Hash digest
SHA256 52fd4fb20acd6e5af86feec9a4a516182b59a97fba5f59bf0a623293456a6b13
MD5 6cef9096c366940bf403715e7e29c10e
BLAKE2b-256 9ce5cbde49d28ec3751903ce78132b1c630b099e9d043e5fb433bb8853ad6bba

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