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.77.07.zip (10.3 kB view details)

Uploaded Source

antipathy-0.77.07.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file antipathy-0.77.07.zip.

File metadata

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

File hashes

Hashes for antipathy-0.77.07.zip
Algorithm Hash digest
SHA256 34267bba8d17c786a97f2b29d3a931f9b4914cd590f181046c773538b7c8254a
MD5 645b20d3abad4ebc088cd95860704991
BLAKE2b-256 30593073b89f6c46dad8f0483c3f3bbcc46b150b9e4e8db157907fa303ea7c4f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for antipathy-0.77.07.tar.gz
Algorithm Hash digest
SHA256 05dd7436cbd5f4977367621abdfbcd9702ffa1ada56080a36ec445cf6b1afbe9
MD5 d435113e67f52dc2fbacb9c355510970
BLAKE2b-256 c5ee4eac2b8a3dcaa52bbe40da7acae748163cc1ee20f6bdca5e19611e4b28bf

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