[svn r37815] path.txt: showing a bit more for string methods
update TODO --HG-- branch : trunk
This commit is contained in:
parent
37a4bfd5ad
commit
0600b1aa36
|
@ -37,10 +37,7 @@ streamline exported API
|
||||||
* make "_" namespace:
|
* make "_" namespace:
|
||||||
py.log -> py._log (pypy!)
|
py.log -> py._log (pypy!)
|
||||||
|
|
||||||
* review py.io and write py.io.dupfile docstring
|
* (done mostly) review py.io and write py.io.dupfile docstring
|
||||||
|
|
||||||
(guido - added docstring, and code looks okay (what was the reason for the
|
|
||||||
review? anything specific?)
|
|
||||||
|
|
||||||
* re-consider what to do with read and write methods of py.path classes (since
|
* re-consider what to do with read and write methods of py.path classes (since
|
||||||
there are places that check for file-ness by doing hasattr(... 'write'))
|
there are places that check for file-ness by doing hasattr(... 'write'))
|
||||||
|
|
|
@ -108,17 +108,18 @@ specific directory.
|
||||||
>>> subdir.join('textfile2.txt').write('spam eggs spam foo bar spam')
|
>>> subdir.join('textfile2.txt').write('spam eggs spam foo bar spam')
|
||||||
>>> results = []
|
>>> results = []
|
||||||
>>> for fpath in dirpath.visit('*.txt'):
|
>>> for fpath in dirpath.visit('*.txt'):
|
||||||
... if 'bar' in fpath.read():
|
... if 'bar' in fpath.read():
|
||||||
... results.append(fpath.basename)
|
... results.append(fpath.basename)
|
||||||
>>> results
|
>>> results
|
||||||
['textfile1.txt', 'textfile2.txt', 'textfile2.txt']
|
['textfile1.txt', 'textfile2.txt', 'textfile2.txt']
|
||||||
|
|
||||||
Joining path types
|
Working with Paths
|
||||||
++++++++++++++++++++
|
++++++++++++++++++++
|
||||||
|
|
||||||
This example shows the :api:`py.path` features to deal with actual paths
|
This example shows the :api:`py.path` features to deal with
|
||||||
(strings). Note that the filesystem is never touched, all operations are
|
filesystem paths Note that the filesystem is never touched,
|
||||||
performed on a string level (so the paths don't have to exist, either)::
|
all operations are performed on a string level (so the paths
|
||||||
|
don't have to exist, either)::
|
||||||
|
|
||||||
>>> p1 = py.path.local('/foo/bar')
|
>>> p1 = py.path.local('/foo/bar')
|
||||||
>>> p2 = p1.join('baz/qux')
|
>>> p2 = p1.join('baz/qux')
|
||||||
|
@ -130,6 +131,13 @@ performed on a string level (so the paths don't have to exist, either)::
|
||||||
>>> p3 = p1 / 'baz/qux' # the / operator allows joining, too
|
>>> p3 = p1 / 'baz/qux' # the / operator allows joining, too
|
||||||
>>> p2 == p3
|
>>> p2 == p3
|
||||||
True
|
True
|
||||||
|
>>> p4 = p1 + ".py"
|
||||||
|
>>> p4.basename == "bar.py"
|
||||||
|
True
|
||||||
|
>>> p4.ext == ".py"
|
||||||
|
True
|
||||||
|
>>> p4.purebasename == "bar"
|
||||||
|
True
|
||||||
|
|
||||||
This should be possible on every implementation of :api:`py.path`, so
|
This should be possible on every implementation of :api:`py.path`, so
|
||||||
regardless of whether the implementation wraps a UNIX filesystem, a Windows
|
regardless of whether the implementation wraps a UNIX filesystem, a Windows
|
||||||
|
|
Loading…
Reference in New Issue