-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
38 lines (27 loc) · 1.24 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Antipathy -- for those tired of ``os.path``
===========================================
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.