This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Support list operations over lines of file-like objects.

All operations avoid iterating except when necessary. Operations that force iteration over the whole file include len() and using negative indexes. In order to avoid excess seeking, all list operations may change the position of the underlying file object.

Start with a file-like object.

>>> import cStringIO
>>> file_ = cStringIO.StringIO("""\
... foo
... bar
... baz
... qux
... """)

Wrap the file-like object in a listfile instance.

>>> from rpatterson import listfile
>>> wrapped = listfile.ListFile(file_)

Lines can be accessed by index.

>>> wrapped[0]
'foo\n'
>>> wrapped[2]
'baz\n'

Negative indexes are supported as well.

>>> wrapped[-1]
'qux\n'
>>> wrapped[-3]
'bar\n'

The length returns the number of lines.

>>> len(wrapped)
4

An index beyond the end of the file raises IndexError.

>>> wrapped[4]
Traceback (most recent call last):
IndexError: list index out of range

Retrieving a slice returns a new wrapper around the same file object.

>>> slice_ = wrapped[1:3]
>>> len(slice_)
2
>>> slice_[0]
'bar\n'
>>> slice_[1]
'baz\n'
>>> slice_ = wrapped[1:][0:2]
>>> len(slice_)
2
>>> slice_[0]
'bar\n'
>>> slice_[1]
'baz\n'

Slice stepping is also supported.

>>> slice_ = wrapped[1::2]
>>> len(slice_)
2
>>> slice_[0]
'bar\n'
>>> slice_[1]
'qux\n'

The wrappers are also iterators suitable for writelines().

>>> list(slice_)
['bar\n', 'qux\n']
>>> out = cStringIO.StringIO()
>>> out.writelines(slice_)
>>> out.getvalue()
'bar\nqux\n'

Changelog

0.1 - 2009-05-27

  • Initial release
Release History

Release History

0.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
rpatterson.listfile-0.1.tar.gz (4.4 kB) Copy SHA256 Checksum SHA256 Source May 28, 2009

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting