Skip to main content
# petl_fwf
This package contains two additional methods which add the ability to read fixed-width files to the fabulous [petl package](https://github.com/petl-developers/petl).

## fromfwf
This is the primary method which this package adds. Usage is straightforward, and similar to other methods in the petl library

```sh
>>> import fromfwf
>>> # setup a sample file
... text = ' 18 5 2\\n2018 5 2\\n20180502'
>>> with open('example.txt', 'w') as f:
... f.write(text)
...
28
>>> table1 = etl.fromfwf('example.txt', widths=[4, 2, 2])
>>> table1
+--------+------+------+
| lines | | |
+========+======+======+
| ' 18' | ' 5' | ' 2' |
+--------+------+------+
| '2018' | ' 5' | ' 2' |
+--------+------+------+
| '2018' | '05' | '02' |
+--------+------+------+
>>> # Specify headers for the file
... table1 = etl.fromfwf('example.txt', widths=[4, 2, 2], header=['year', 'month', 'day'])
>>> table1
+--------+-------+------+
| year | month | day |
+========+=======+======+
| ' 18' | ' 5' | ' 2' |
+--------+-------+------+
| '2018' | ' 5' | ' 2' |
+--------+-------+------+
| '2018' | '05' | '02' |
+--------+-------+------+
```

## skiplast
This method will skip the last n rows of a table.
```sh
>>> import petl as etl
>>> table1 = [['foo', 'bar'],
... ['a', 1],
... ['b', 2],
... ['c', 3],
... ['FOOTER ROW']]
>>> table2 = etl.skiplast(table1, 1)
>>> table2
+-----+-----+
| foo | bar |
+=====+=====+
| 'a' | 1 |
+-----+-----+
| 'b' | 2 |
+-----+-----+
| 'c' | 3 |
+-----+-----+
```

Release files for petl-fwf 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for petl-fwf 0.0.2
File Size Uploaded
petl_fwf-0.0.2.tar.gz 5.3 kB Details

Release files / petl_fwf-0.0.2.tar.gz

Download URL petl_fwf-0.0.2.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
49587006a26a97cdddc753f9197a4493b65134bcf5d3ae841ecf3bb215fd2ab4
BLAKE2b-256 checksum
How to use checksums
e7f401da5477a4595537bbef0f7fef0373856a298b365a17f2d5661a338febd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page