Skip to main content

Enable handle of csv, xls and xlsx files getting column header

Project description

The PyHeaderFile helps the work with files that have extensions csv, xls and xlsx.

This project aims reading files over the header (column names). With this module we can handle Csv, Xls and Xlsx files using same interface. Thus, we can convert extensions, strip values in lines, change cell style of Excel files, read a specific Excel file, read an specific cell and read just some headers.

Install

pip install pyheaderfile

How to use

Class csv

Read csv

file = Csv(name=’file.csv’)
for row in file.read():
    print row

Set Header

file.header = ['col1', 'col2','col3']

Create csv

file = Csv(name='filename.csv', header=['col1','col2','col3'])

Write list csv

file.write(['col1','col2','col3'])

Write dict csv

file.write(dict(header=value))

Class Xls

Read xls

file = Xls(name=’file.xls’)
for row in file.read():
    print row

Set Header

file.header = ['col1', 'col2','col3']

Create xls

file = Xls(name='filename.xls', header=['col1','col2','col3'])

Write list

file.write(['col1','col2','col3'])

Write dict

file.write(dict(header=value))

Class Xlsx

Read

file = Xlsx(name=’file.xlsx’)
for row in file.read():
    print row

Set Header

file.header = ['col1', 'col2','col3']

Create file

file = Xlsx(name='filename.xlsx', header=['col1','col2','col3'])

Write list

file.write(['col_val1','col_val2','col_val3'])

Write dict

file.write(dict(header=value))

Save file

file.save()

Tricks

Modifying extensions, name and header

q = Xls()
x = Xlsx(name='filename.xlsx')
x.name = 'ugly file name'
x.header = ['col1', 'col2','col3']
q(x)

Guess file type

To guess what class you need to open just use:

::

filename = ‘test.xls’ my_file = guess_type(filename)

And for a SUPERCOMBO you can guess and convert everything!

::

my_file = guess_type(filename) convert_to = Xls() my_file.name = ‘beautiful_name’ my_file.header = [‘col1’, ‘col2’,’col3’] convert_to(my_file) # now yout file is a xls file ;)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyheaderfile-0.2.1.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file pyheaderfile-0.2.1.tar.gz.

File metadata

File hashes

Hashes for pyheaderfile-0.2.1.tar.gz
Algorithm Hash digest
SHA256 056005cb9b1db3ff8780d4ca738ee70ebbf71404d070333081eb39407e60d9a6
MD5 100ef1b018858341bdc4c1584ec1ab24
BLAKE2b-256 ffca7d4bef00c5db0a449bd40c4fe4c5bb4c8f138bae8b2f9ff9cdedc1e44a45

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page